Search in sources :

Example 1 with PointPairDistance

use of org.locationtech.jts.algorithm.distance.PointPairDistance in project qupath by qupath.

the class DistanceTools method computeDistance.

/**
 * Compute the shortest distance from a coordinate to a target geometry.
 * @param coord the coordinate
 * @param geometry the target geometry
 * @param locator a locator created for the target Geometry or null; if available, computations may be faster
 * @return
 */
public static double computeDistance(Coordinate coord, Geometry geometry, PointOnGeometryLocator locator) {
    if (locator == null) {
        PointPairDistance dist = new PointPairDistance();
        DistanceToPoint.computeDistance(geometry, coord, dist);
        return dist.getDistance();
    }
    int location = locator.locate(coord);
    double distance = 0;
    if (location == Location.EXTERIOR) {
        PointPairDistance dist = new PointPairDistance();
        DistanceToPoint.computeDistance(geometry, coord, dist);
        distance = dist.getDistance();
    }
    return distance;
}
Also used : PointPairDistance(org.locationtech.jts.algorithm.distance.PointPairDistance) DistanceToPoint(org.locationtech.jts.algorithm.distance.DistanceToPoint)

Aggregations

DistanceToPoint (org.locationtech.jts.algorithm.distance.DistanceToPoint)1 PointPairDistance (org.locationtech.jts.algorithm.distance.PointPairDistance)1