[GIS] Calculate distance of point along a line using NetTopologySuite

nettopologysuite

I am looking to calculate the distance along a line of a point using NetTopologySuite.

Indications are that the distanceOp may have something to do with it, given that I can a point on a line closest to another geometry. However how to determine the distance along the line of that point? I can certainly determine what that distance is myself through some code – but I would have through NTS would already have this covered off.

Anyone have any pointers?

Thanks,

Matt

Best Answer

LinearReferencing.LengthLocationMap will get you the distance of point along a line.

Computes the LinearLocation for a given length along a linear Geometry.Negative lengths are measured in reverse from end of the linear geometry. Out-of-range values are clamped.

using NetTopologySuite.LinearReferencing;

string wkt = "LINESTRING (0 0, 10 0, 10 10)";
WKTReader rdr = new WKTReader();
IGeometry g1 = rdr.Read(wkt);

ILineString linearGeometry = (ILineString)g1;
Coordinate pt = new Coordinate(10,5);
LinearLocation linearLocation = LocationIndexOfPoint.IndexOf(linearGeometry, pt);
double length = LengthLocationMap.GetLength(linearGeometry, linearLocation);
Related Question