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):
Thanks so much for any help..
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
Else
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
Next
Could this be a rounding issue, because DotSpatial.Topology.Coordinate truncates lat/lng values beyond 6 decimals?Thanks so much for any help..