Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?



share|improve this question

2 Answers 2

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);
share|improve this answer

I don't use the JTS/NTS APIs much myself but I would look at the LengthIndexedLine class:

Supports linear referencing along a linear Geometry using the length along the line as the index. Negative length values are taken as measured in the reverse direction from the end of the geometry. Out-of-range index values are handled by clamping them to the valid range of values. Non-simple lines (i.e. which loop back to cross or touch themselves) are supported.

Particularly, look at the project method:

Computes the index for the closest point on the line to the given point. If more than one point has the closest distance the first one along the line is returned. (The point does not necessarily have to lie precisely on the line.)

I am assuming that the value returned is the actual length along the line to that point. I could be off base though, as I haven't tried it.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.