getSegment method
Gets a {@link LineSegment} representing the segment of the given linear {@link Geometry} which contains this location.
@param linearGeom a linear geometry @return the LineSegment containing the location
Implementation
LineSegment getSegment(Geometry linearGeom) {
LineString lineComp = linearGeom.getGeometryN(componentIndex) as LineString;
Coordinate p0 = lineComp.getCoordinateN(segmentIndex);
// check for endpoint - return last segment of the line if so
if (segmentIndex >= numSegments(lineComp)) {
Coordinate prev = lineComp.getCoordinateN(lineComp.getNumPoints() - 2);
return new LineSegment.fromCoordinates(prev, p0);
}
Coordinate p1 = lineComp.getCoordinateN(segmentIndex + 1);
return new LineSegment.fromCoordinates(p0, p1);
}