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;
}
Aggregations