So it sounds like the input points are not necessarily precisely at vertices. In this case either LengthIndexedLine or LocationIndexedLine can be used.

Note that each of these has a project(Coordinate) method, which might eliminate the need to call DistanceOp.nearestPoints.

On Wed, Jul 2, 2014 at 1:48 PM, André Salvati <> wrote:
I'm trying to segment a bus line by their bus stops.

It works this way:

1) user gives me 2 points (don't know if they belong to the LineString).
2) code gets the LineString nearest point for each of them with DistanceOp.nearestPoints(lineString, point). Now I'm sure that they are at least near the LineString.
3) Cut the segment delimited by these nearest points (as a new LineString).

So, in the beginning I said incorrectly "2 points inside the last one". The correct would be: "2 points near the LineString".

Do you think LocationIndexedLine would be more appropriate??

2014-07-02 17:34 GMT-03:00 Martin Davis <>:

It might better to use LocationIndexedLine for this - it uses exact vertex indices for locations, rather than computed lengths.  That makes it more precise when you are working directly with vertex indices.

On Wed, Jul 2, 2014 at 12:20 PM, André Salvati <> wrote:
Very simple implementation where "line" is a LineString.

Thanks Martin.

LengthIndexedLine l_i = new LengthIndexedLine(line);
Coordinate[] csSeg = l_i.extractLine(l_i.indexOf(cInicio), l_i.indexOf(cFim)).getCoordinates();

2014-07-02 14:47 GMT-03:00 Martin Davis <>:

On Tue, Jul 1, 2014 at 10:00 AM, André Salvati <> wrote:

1) is there a function to extract a segment (LineString) from a bigger LineString given 2 points inside the last one?

2) I also would like to get the size of the obtained segment. Is it possible?


Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
Jts-topo-suite-user mailing list