I am trying to use the Net Topology Suite (v 1.13.2) in a simple console app to find points in a shape file that contains road information.
I have loaded the shape file and stored the data in a typed list, and I have checked that the data looks as expected..
When I iterate around the list I want to find if a given point is within any of the shapes in the shape file.
Sounds straightforward!
my code looks like;
private static Feature FindPoint(double lat, double lon)
{
Coordinate c = new Coordinate(lat, lon);
IGeometry g = factory.CreateGeometry(Geometry.DefaultFactory.CreatePoint(c));
foreach(Feature f in Features)
{
if (f.Geometry.Overlaps(g))
return f;
if (f.Geometry.EnvelopeInternal.Contains(c))
return f;
if (f.Geometry.Boundary.Contains(g))
return f;
if (f.Geometry.Contains(g))
return f;
}
return null;
}
None of these statements, or any of the others I have tried return any indication that the point is within any of the shapes in.
I am trying with a Lat and Long I picked from one of the shapes in the file! SO it should be there.
Any ideas as to where I am going wrong?
@Habib, I have checked and the geometry type is LineString, but the Envelope is defined as a polygon.
I have looked at the link you sent, new code below;
DistanceOp dop = new DistanceOp(f.Geometry,g);
var np = dop.NearestPoints();
var d = dop.Distance();
Tried to do as indicated there, but the answer I get for the distance between the point I have chosen and the line is 71.236662957979718.
71.236662957979718 what? cm, metres, degrees???
Strange anyway, as I have picked a point on one of the lines, so I would expect an answer of 0.