/** * Computes the subline of a {@link LineString} between * two {@link LinearLocation}s on the line. * If the start location is after the end location, * the computed linear geometry has reverse orientation to the input line. * * @param line the line to use as the baseline * @param start the start location * @param end the end location * @return the extracted subline */ public static Geometry extract(Geometry line, LinearLocation start, LinearLocation end) { ExtractLineByLocation ls = new ExtractLineByLocation(line); return ls.extract(start, end); }
/** * Extracts a subline of the input. * If <code>end < start</code> the linear geometry computed will be reversed. * * @param start the start location * @param end the end location * @return a linear geometry */ public Geometry extract(LinearLocation start, LinearLocation end) { if (end.compareTo(start) < 0) { return reverse(computeLinear(end, start)); } return computeLinear(start, end); }
/** * Computes the {@link LineString} for the interval * on the line between the given indices. * If the start location is after the end location, * the computed linear geometry has reverse orientation to the input line. * * @param startIndex the index of the start of the interval * @param endIndex the index of the end of the interval * @return the linear geometry between the indices */ public Geometry extractLine(LinearLocation startIndex, LinearLocation endIndex) { return ExtractLineByLocation.extract(linearGeom, startIndex, endIndex); }
/** * Computes the {@link LineString} for the interval * on the line between the given indices. * If the endIndex lies before the startIndex, * the computed geometry is reversed. * * @param startIndex the index of the start of the interval * @param endIndex the index of the end of the interval * @return the linear interval between the indices */ public Geometry extractLine(double startIndex, double endIndex) { double startIndex2 = clampIndex(startIndex); double endIndex2 = clampIndex(endIndex); // if extracted line is zero-length, resolve start lower as well to ensure they are equal boolean resolveStartLower = startIndex2 == endIndex2; LinearLocation startLoc = locationOf(startIndex2, resolveStartLower); // LinearLocation endLoc = locationOf(endIndex2, true); // LinearLocation startLoc = locationOf(startIndex2); LinearLocation endLoc = locationOf(endIndex2); return ExtractLineByLocation.extract(linearGeom, startLoc, endLoc); }