PointInShapefile not working anymore in 5.2 and 5.3?

The PointInShapefile function used to be working on MWG5 but seems to have stopped working in V5.2 and the latest V5.3 (Win 11, VS 2019). I seem to remember there were some problems with it in the past. There is an easy workaround (see vb.net code below), but just for the record for in case I made a mistake…
Cheers,
Francis.

Private Sub _Map_MouseDownEvent(sender As Object, e As _DMapEvents_MouseDownEvent) Handles _Map.MouseDownEvent

Dim ProjX As Double, ProjY As Double
_Map.PixelToProj(e.x, e.y, ProjX, ProjY)
Dim shp As Shapefile = _Map.get_Shapefile(0)
’ Allways returns -1!!
Dim shpindex As Integer = shp.PointInShapefile(ProjX, ProjY)
Dim idx As Integer
’ Works fine
For idx = 0 To shp.NumShapes - 1
If shp.PointInShape(idx, ProjX, ProjY) Then
Exit For
End If
Next
UcMapWinGIS51.tsslMessages.Text = "Idx = " + idx.ToString
End Sub

Hello @pan054

I’m sorry I don’t really have time to look further into this, but I do notice that you have not called the BeginPointInShapefile and EndPointInShapefile functions, which build and then tear down a cache. Although I don’t think the calls are necessary, I think that it’s worth trying to see if that makes a difference.

Regards,
Jerry.

Hi Jerry,
Thanks for your quick reply, where would we be without you.
It is crazy, but it does indeed work :thinking:! It shouldn’t but it does, so thanks very much for your suggestion!
Cheers
Francis

FYI
I compared the ‘do it yourself’ code against the Begin/End code, and found that the Begin/End code is always faster. How much faster depends on the place of the shape in the shapefile table.

It’s strange, for some reason BeginPointInShapefile function raises an exception for me. Perhaps something else is needed?