Class DistanceOp

Hierarchy: Object , DistanceOp
public class DistanceOp
Find two points on two Geometrys which lie within a given distance, or else are the nearest points on the geometries (in which case this also provides the distance between the geometries).

The distance computation also finds a pair of points in the input geometries which have the minimum distance between them. If a point lies in the interior of a line segment, the coordinate computed is a close approximation to the exact point.

Empty geometry collection components are ignored.

The algorithms used are straightforward O(n^2) comparisons. This worst-case performance could be improved on by using Voronoi techniques or spatial indexes.

Other

  • version: 1.7
public DistanceOp(Geometry g0, Geometry g1)
Constructs a DistanceOp that computes the distance and nearest points between the two specified geometries.
Parameters:
g0 - g0 a Geometry
g1 - g1 a Geometry
public DistanceOp(Geometry g0, Geometry g1, double terminateDistance)
Constructs a DistanceOp that computes the distance and nearest points between the two specified geometries.
Parameters:
g0 - g0 a Geometry
g1 - g1 a Geometry
terminateDistance - terminateDistance the distance on which to terminate the search
public static double distance(Geometry g0, Geometry g1)
Compute the distance between the nearest points of two geometries.
Parameters:
g0 - g0 a Geometry
g1 - g1 another Geometry
Returns:
the distance between the geometries
public static boolean isWithinDistance(Geometry g0, Geometry g1, double distance)
Test whether two geometries lie within a given distance of each other.
Parameters:
g0 - g0 a Geometry
g1 - g1 another Geometry
distance - distance the distance to test
Returns:
true if g0.distance(g1) <= distance
public static Coordinate[] nearestPoints(Geometry g0, Geometry g1)
Compute the the nearest points of two geometries. The points are presented in the same order as the input Geometries.
Parameters:
g0 - g0 a Geometry
g1 - g1 another Geometry
Returns:
the nearest points in the geometries
public static Coordinate[] closestPoints(Geometry g0, Geometry g1)
Compute the the closest points of two geometries. The points are presented in the same order as the input Geometries.
Parameters:
g0 - g0 a Geometry
g1 - g1 another Geometry
Returns:
the closest points in the geometries
Deprecation:
renamed to nearestPoints
public double distance()
Report the distance between the nearest points on the input geometries.
Returns:
the distance between the geometries or 0 if either input geometry is empty
Throws:
IllegalArgumentException - IllegalArgumentException if either input geometry is null
public Coordinate[] nearestPoints()
Report the coordinates of the nearest points in the input geometries. The points are presented in the same order as the input Geometries.
Returns:
a pair of Coordinates of the nearest points
public Coordinate[] closestPoints()
Returns:
a pair of Coordinates of the nearest points
Deprecation:
renamed to nearestPoints
public GeometryLocation[] nearestLocations()
Report the locations of the nearest points in the input geometries. The locations are presented in the same order as the input Geometries.
Returns:
a pair of GeometryLocations for the nearest points
public GeometryLocation[] closestLocations()
Returns:
a pair of GeometryLocations for the nearest points
Deprecation:
renamed to nearestLocations