computeLine method
Assumes input is valid (e.g. start <= end)
@param start @param end @return a linear geometry
Implementation
LineString computeLine(LinearLocation start, LinearLocation end) {
List<Coordinate> coordinates = line.getCoordinates();
CoordinateList newCoordinates = new CoordinateList();
int startSegmentIndex = start.getSegmentIndex();
if (start.getSegmentFraction() > 0.0) startSegmentIndex += 1;
int lastSegmentIndex = end.getSegmentIndex();
if (end.getSegmentFraction() == 1.0) lastSegmentIndex += 1;
if (lastSegmentIndex >= coordinates.length)
lastSegmentIndex = coordinates.length - 1;
// not needed - LinearLocation values should always be correct
//Assert.isTrue(end.getSegmentFraction() <= 1.0, "invalid segment fraction value");
if (!start.isVertex()) newCoordinates.add(start.getCoordinate(line));
for (int i = startSegmentIndex; i <= lastSegmentIndex; i++) {
newCoordinates.add(coordinates[i]);
}
if (!end.isVertex()) newCoordinates.add(end.getCoordinate(line));
// ensure there is at least one coordinate in the result
if (newCoordinates._backingList.length <= 0)
newCoordinates.add(start.getCoordinate(line));
List<Coordinate> newCoordinateArray = newCoordinates.toCoordinateArray();
/**
* Ensure there is enough coordinates to build a valid line.
* Make a 2-point line with duplicate coordinates, if necessary.
* There will always be at least one coordinate in the coordList.
*/
if (newCoordinateArray.length <= 1) {
newCoordinateArray = <Coordinate>[
newCoordinateArray[0],
newCoordinateArray[0]
];
}
return line.getFactory().createLineString(newCoordinateArray);
}