Very simple point in Polygon test not working

Feb 8 at 3:14 PM
Edited Feb 8 at 3:16 PM
I tried to find the answer for hours, but I ended up with nothing.. this is a mystery to me.

The following code should do a simple point in Polygon test, but it always returns false for the intersection (I am definitely providing lat/lng coordinates that lies within the polygon):
      'load Shapefile
      Dim filedialog As OpenFileDialog = New OpenFileDialog()
        filedialog.Title = "Select shapefile (WGS1984 Projection)"
        filedialog.InitialDirectory = "C:\temp" 'DE_WGS1984.shp
        filedialog.RestoreDirectory = True
        If filedialog.ShowDialog() = DialogResult.OK Then
            TextBox4.Text = filedialog.FileName
            Exit Sub
        End If
        Dim ShapefilePoly As Shapefile = Shapefile.OpenFile(TextBox4.Text)
      'lngP/latP is the coordinate to test against the shapefile, e.g. 13.380025, 52.52972

                Dim PhotoPoint As New DotSpatial.Topology.Coordinate(lngP, latP)
                For Each f As DotSpatial.Data.Feature In ShapefilePoly.Features
                    Dim pg As DotSpatial.Topology.Polygon = TryCast(f.BasicGeometry, Polygon)
                    If pg IsNot Nothing Then
                        If pg.Contains(New DotSpatial.Topology.Point(PhotoPoint)) Then
                            LiesWithin = True 'never triggered
                            Exit Function
                        End If
                    End If
Could this be a rounding issue, because DotSpatial.Topology.Coordinate truncates lat/lng values beyond 6 decimals?
Thanks so much for any help..
Feb 9 at 9:00 AM
Edited Feb 9 at 3:03 PM
I am a step further.. it seems to have something to do with the Shapefiles I am using. There are some types of Shapefiles where the code works, for some other ones, it doesn't.

Ok, it gets even stranger: The one feature that works for selection is located in Toronto, Highpark. The other feature that doesn't work is located in Berlin, Speeinsel.

Now if I move the Highpark-feature to Berlin Spreeinsel, it also doesn't work anymore (=finds no intersecting points). This is a real mystery.. Both shapes draw perfectly fine on the map.


Ok.. please forgive me for bothering you. It was a completely different issue all the time - the list of coordinates I was passing on was erroneously filtered, such as that in one shapefile, coordinates the right coordinates would get passed on, in another case, coordinates from somewhere completely different would get passed on. I am really suprised I didn't notice this issue all the time..

Sorry again, and thanks for Dotspatial!

All the best, Grom
Marked as answer by Gromhelm on 2/9/2017 at 7:03 AM