Class DistanceOp
java.lang.Object
org.locationtech.jts.operation.distance.DistanceOp
Find two points on two
Geometry
s 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.
The algorithms used are straightforward O(n^2) comparisons. This worst-case performance could be improved on by using Voronoi techniques or spatial indexes.
- Version:
- 1.7
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Geometry[]
private double
private GeometryLocation[]
private PointLocator
private double
-
Constructor Summary
ConstructorsConstructorDescriptionDistanceOp
(Geometry g0, Geometry g1) Constructs a DistanceOp that computes the distance and nearest points between the two specified geometries.DistanceOp
(Geometry g0, Geometry g1, double terminateDistance) Constructs a DistanceOp that computes the distance and nearest points between the two specified geometries. -
Method Summary
Modifier and TypeMethodDescriptionDeprecated.renamed to nearestLocationsDeprecated.renamed to nearestPointsstatic Coordinate[]
closestPoints
(Geometry g0, Geometry g1) Deprecated.renamed to nearestPointsprivate void
private void
computeContainmentDistance
(int polyGeomIndex, GeometryLocation[] locPtPoly) private void
computeContainmentDistance
(List locs, List polys, GeometryLocation[] locPtPoly) private void
computeContainmentDistance
(GeometryLocation ptLoc, Polygon poly, GeometryLocation[] locPtPoly) private void
Computes distance between facets (lines and points) of input geometries.private void
private void
computeMinDistance
(LineString line0, LineString line1, GeometryLocation[] locGeom) private void
computeMinDistance
(LineString line, Point pt, GeometryLocation[] locGeom) private void
computeMinDistanceLines
(List lines0, List lines1, GeometryLocation[] locGeom) private void
computeMinDistanceLinesPoints
(List lines, List points, GeometryLocation[] locGeom) private void
computeMinDistancePoints
(List points0, List points1, GeometryLocation[] locGeom) double
distance()
Report the distance between the nearest points on the input geometries.static double
Compute the distance between the nearest points of two geometries.static boolean
isWithinDistance
(Geometry g0, Geometry g1, double distance) Test whether two geometries lie within a given distance of each other.Report the locations of the nearest points in the input geometries.Report the coordinates of the nearest points in the input geometries.static Coordinate[]
nearestPoints
(Geometry g0, Geometry g1) Compute the the nearest points of two geometries.private void
updateMinDistance
(GeometryLocation[] locGeom, boolean flip)
-
Field Details
-
geom
-
terminateDistance
private double terminateDistance -
ptLocator
-
minDistanceLocation
-
minDistance
private double minDistance
-
-
Constructor Details
-
DistanceOp
Constructs a DistanceOp that computes the distance and nearest points between the two specified geometries.- Parameters:
g0
- a Geometryg1
- a Geometry
-
DistanceOp
Constructs a DistanceOp that computes the distance and nearest points between the two specified geometries.- Parameters:
g0
- a Geometryg1
- a GeometryterminateDistance
- the distance on which to terminate the search
-
-
Method Details
-
distance
Compute the distance between the nearest points of two geometries. -
isWithinDistance
Test whether two geometries lie within a given distance of each other. -
nearestPoints
Compute the the nearest points of two geometries. The points are presented in the same order as the input Geometries. -
closestPoints
Deprecated.renamed to nearestPointsCompute the the closest points of two geometries. The points are presented in the same order as the input Geometries. -
distance
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
- if either input geometry is null
-
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
Coordinate
s of the nearest points
-
closestPoints
Deprecated.renamed to nearestPoints- Returns:
- a pair of
Coordinate
s of the nearest points
-
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
GeometryLocation
s for the nearest points
-
closestLocations
Deprecated.renamed to nearestLocations- Returns:
- a pair of
GeometryLocation
s for the nearest points
-
updateMinDistance
-
computeMinDistance
private void computeMinDistance() -
computeContainmentDistance
private void computeContainmentDistance() -
computeContainmentDistance
-
computeContainmentDistance
-
computeContainmentDistance
private void computeContainmentDistance(GeometryLocation ptLoc, Polygon poly, GeometryLocation[] locPtPoly) -
computeFacetDistance
private void computeFacetDistance()Computes distance between facets (lines and points) of input geometries. -
computeMinDistanceLines
-
computeMinDistancePoints
-
computeMinDistanceLinesPoints
-
computeMinDistance
-
computeMinDistance
-