/** * 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.) * * @param pt a point on the line * @return the index of the point */ public double project(Coordinate pt) { return LengthIndexOfPoint.indexOf(linearGeom, pt); }
/** * Finds the nearest index along the linear {@link Geometry} * to a given {@link Coordinate} * after the specified minimum index. * If possible the location returned will be strictly greater than the * <code>minLocation</code>. * If this is not possible, the * value returned will equal <code>minLocation</code>. * (An example where this is not possible is when * minLocation = [end of line] ). * * @param inputPt the coordinate to locate * @param minIndex the minimum location for the point location * @return the location of the nearest point */ public double indexOfAfter(Coordinate inputPt, double minIndex) { if (minIndex < 0.0) return indexOf(inputPt); // sanity check for minIndex at or past end of line double endIndex = linearGeom.getLength(); if (endIndex < minIndex) return endIndex; double closestAfter = indexOfFromStart(inputPt, minIndex); /** * Return the minDistanceLocation found. */ Assert.isTrue(closestAfter >= minIndex, "computed index is before specified minimum index"); return closestAfter; }
/** * Computes the minimum index for a point on the line. * If the line is not simple (i.e. loops back on itself) * a single point may have more than one possible index. * In this case, the smallest index is returned. * * The supplied point does not <i>necessarily</i> have to lie precisely * on the line, but if it is far from the line the accuracy and * performance of this function is not guaranteed. * Use {@link #project} to compute a guaranteed result for points * which may be far from the line. * * @param pt a point on the line * @return the minimum index of the point * * @see #project(Coordinate) */ public double indexOf(Coordinate pt) { return LengthIndexOfPoint.indexOf(linearGeom, pt); }
public static double indexOf(Geometry linearGeom, Coordinate inputPt) { LengthIndexOfPoint locater = new LengthIndexOfPoint(linearGeom); return locater.indexOf(inputPt); }