Class DiscreteHausdorffDistance
- java.lang.Object
-
- org.locationtech.jts.algorithm.distance.DiscreteHausdorffDistance
-
public class DiscreteHausdorffDistance extends java.lang.Object
An algorithm for computing a distance metric which is an approximation to the Hausdorff Distance based on a discretization of the inputGeometry
. The algorithm computes the Hausdorff distance restricted to discrete points for one of the geometries. The points can be either the vertices of the geometries (the default), or the geometries with line segments densified by a given fraction. Also determines two points of the Geometries which are separated by the computed distance.This algorithm is an approximation to the standard Hausdorff distance. Specifically,
for all geometries a, b: DHD(a, b) <= HD(a, b)
The approximation can be made as close as needed by densifying the input geometries. In the limit, this value will approach the true Hausdorff distance:DHD(A, B, densifyFactor) -> HD(A, B) as densifyFactor -> 0.0
The default approximation is exact or close enough for a large subset of useful cases. Examples of these are:- computing distance between Linestrings that are roughly parallel to each other, and roughly equal in length. This occurs in matching linear networks.
- Testing similarity of geometries.
A = LINESTRING (0 0, 100 0, 10 100, 10 100) B = LINESTRING (0 100, 0 10, 80 10) DHD(A, B) = 22.360679774997898 HD(A, B) ~= 47.8
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DiscreteHausdorffDistance.MaxDensifiedByFractionDistanceFilter
static class
DiscreteHausdorffDistance.MaxPointDistanceFilter
-
Field Summary
Fields Modifier and Type Field Description private double
densifyFrac
Value of 0.0 indicates that no densification should take placeprivate Geometry
g0
private Geometry
g1
private PointPairDistance
ptDist
-
Constructor Summary
Constructors Constructor Description DiscreteHausdorffDistance(Geometry g0, Geometry g1)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
compute(Geometry g0, Geometry g1)
private void
computeOrientedDistance(Geometry discreteGeom, Geometry geom, PointPairDistance ptDist)
double
distance()
static double
distance(Geometry g0, Geometry g1)
static double
distance(Geometry g0, Geometry g1, double densifyFrac)
Coordinate[]
getCoordinates()
double
orientedDistance()
void
setDensifyFraction(double densifyFrac)
Sets the fraction by which to densify each segment.
-
-
-
Field Detail
-
g0
private Geometry g0
-
g1
private Geometry g1
-
ptDist
private PointPairDistance ptDist
-
densifyFrac
private double densifyFrac
Value of 0.0 indicates that no densification should take place
-
-
Method Detail
-
setDensifyFraction
public void setDensifyFraction(double densifyFrac)
Sets the fraction by which to densify each segment. Each segment will be (virtually) split into a number of equal-length subsegments, whose fraction of the total length is closest to the given fraction.- Parameters:
densifyFrac
-
-
distance
public double distance()
-
orientedDistance
public double orientedDistance()
-
getCoordinates
public Coordinate[] getCoordinates()
-
computeOrientedDistance
private void computeOrientedDistance(Geometry discreteGeom, Geometry geom, PointPairDistance ptDist)
-
-