GEOS 3.16.0dev
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
geos::algorithm::distance::DirectedHausdorffDistance Class Reference

#include <DirectedHausdorffDistance.h>

Public Types

using PointPair = std::array< geom::CoordinateXY, 2 >
 JTS returns Coordinate[]; std::array is the C++ equivalent pair.
 

Public Member Functions

 DirectedHausdorffDistance (const geom::Geometry &geom)
 
 DirectedHausdorffDistance (const DirectedHausdorffDistance &)=delete
 
DirectedHausdorffDistance & operator= (const DirectedHausdorffDistance &)=delete
 
std::optional< PointPair > farthestPoints (const geom::Geometry &geom) const
 
std::optional< PointPair > farthestPoints (const geom::Geometry &geom, double tolerance) const
 
bool isFullyWithinDistance (const geom::Geometry &geom, double maxDistance) const
 
bool isFullyWithinDistance (const geom::Geometry &geom, double maxDistance, double tolerance) const
 

Static Public Member Functions

static double distance (const geom::Geometry &a, const geom::Geometry &b)
 
static double distance (const geom::Geometry &a, const geom::Geometry &b, double tolerance)
 
static std::optional< PointPair > distancePoints (const geom::Geometry &a, const geom::Geometry &b)
 
static std::optional< PointPair > distancePoints (const geom::Geometry &a, const geom::Geometry &b, double tolerance)
 
static double hausdorffDistance (const geom::Geometry &a, const geom::Geometry &b)
 
static std::optional< PointPair > hausdorffDistancePoints (const geom::Geometry &a, const geom::Geometry &b)
 
static bool isFullyWithinDistance (const geom::Geometry &a, const geom::Geometry &b, double maxDistance)
 
static bool isFullyWithinDistance (const geom::Geometry &a, const geom::Geometry &b, double maxDistance, double tolerance)
 

Friends

class DHDSegment
 

Detailed Description

Computes the directed Hausdorff distance from one geometry to another. The directed Hausdorff distance is the maximum distance any point on a query geometry A can be from a target geometry B. Equivalently, every point in the query geometry is within that distance of the target geometry. The class can compute a pair of points at which the distance is attained: [ farthest A point, nearest B point ].

The directed Hausdorff distance (DHD) is defined as:

DHD(A,B) = max a ∈ A (max b ∈ B (distance(a, b) )

DHD is asymmetric: DHD(A,B) may not be equal to DHD(B,A). Hence it is not a distance metric. The Hausdorff distance is a symmetric distance metric defined as:

HD(A,B) = max(DHD(A,B), DHD(B,A))

This can be computed via the hausdorffDistancePoints(Geometry, Geometry) function.

Points, lines and polygons are supported as input. If the query geometry is polygonal, the point at maximum distance may occur in the interior of a query polygon. For a polygonal target geometry the point always lies on the boundary.

The directed Hausdorff distance can be used to test whether a geometry lies fully within a given distance of another one. The isFullyWithinDistance(Geometry, double) function is provided to execute this test efficiently. It implements heuristic checks and short-circuiting to improve performance.

The class can be used in prepared mode. Creating an instance on a target geometry caches indexes for that geometry. Then farthestPoints(Geometry) or isFullyWithinDistance(Geometry, double) can be called efficiently for multiple query geometries.

If the Hausdorff distance is attained at a non-vertex of the query geometry, the location must be approximated. The algorithm uses a distance tolerance to control the approximation accuracy. The tolerance is automatically determined to balance between accuracy and performance. If more accuracy is desired some function signatures are provided which allow specifying a distance tolerance.

This algorithm is easier to use, more accurate, and much faster than DiscreteHausdorffDistance.

Author
Martin Davis

Constructor & Destructor Documentation

◆ DirectedHausdorffDistance()

geos::algorithm::distance::DirectedHausdorffDistance::DirectedHausdorffDistance ( const geom::Geometry &  geom)
explicit

Create a new instance for a target geometry.

Parameters
geomthe geometry to compute the distance from

Member Function Documentation

◆ distance() [1/2]

static double geos::algorithm::distance::DirectedHausdorffDistance::distance ( const geom::Geometry &  a,
const geom::Geometry &  b 
)
static

Computes the directed Hausdorff distance of a query geometry A from a target one B.

Parameters
athe query geometry
bthe target geometry
Returns
the directed Hausdorff distance, or NaN if an input is empty

◆ distance() [2/2]

static double geos::algorithm::distance::DirectedHausdorffDistance::distance ( const geom::Geometry &  a,
const geom::Geometry &  b,
double  tolerance 
)
static

Computes the directed Hausdorff distance of a query geometry A from a target one B, up to a given distance accuracy.

Parameters
athe query geometry
bthe target geometry
tolerancethe accuracy distance tolerance
Returns
the directed Hausdorff distance, or NaN if an input is empty

◆ distancePoints() [1/2]

static std::optional< PointPair > geos::algorithm::distance::DirectedHausdorffDistance::distancePoints ( const geom::Geometry &  a,
const geom::Geometry &  b 
)
static

Computes a line containing a pair of points which attain the directed Hausdorff distance of a query geometry A from a target one B.

Parameters
athe query geometry
bthe target geometry
Returns
a pair of points [ptA, ptB] demonstrating the distance, or empty if an input is empty

◆ distancePoints() [2/2]

static std::optional< PointPair > geos::algorithm::distance::DirectedHausdorffDistance::distancePoints ( const geom::Geometry &  a,
const geom::Geometry &  b,
double  tolerance 
)
static

Computes a line containing a pair of points which attain the directed Hausdorff distance of a query geometry A from a target one B, up to a given distance accuracy.

Parameters
athe query geometry
bthe target geometry
tolerancethe accuracy distance tolerance
Returns
a pair of points [ptA, ptB] demonstrating the distance, or empty if an input is empty

◆ farthestPoints() [1/2]

std::optional< PointPair > geos::algorithm::distance::DirectedHausdorffDistance::farthestPoints ( const geom::Geometry &  geom) const

Computes a pair of points which attain the directed Hausdorff distance of a query geometry A from the target B. If either geometry is empty the result is empty.

Parameters
geomthe query geometry
Returns
a pair of points [ptA, ptB] attaining the distance, or empty if an input is empty

◆ farthestPoints() [2/2]

std::optional< PointPair > geos::algorithm::distance::DirectedHausdorffDistance::farthestPoints ( const geom::Geometry &  geom,
double  tolerance 
) const

Computes a pair of points which attain the directed Hausdorff distance of a query geometry A from the target B, up to a given distance accuracy. If either geometry is empty the result is empty.

Parameters
geomthe query geometry
tolerancethe approximation distance tolerance
Returns
a pair of points [ptA, ptB] attaining the distance, or empty if an input is empty

◆ hausdorffDistance()

static double geos::algorithm::distance::DirectedHausdorffDistance::hausdorffDistance ( const geom::Geometry &  a,
const geom::Geometry &  b 
)
static

Computes the symmetric Hausdorff distance between two geometries. This is the maximum of the two directed Hausdorff distances.

Parameters
aa geometry
ba geometry
Returns
the Hausdorff distance, or NaN if an input is empty

◆ hausdorffDistancePoints()

static std::optional< PointPair > geos::algorithm::distance::DirectedHausdorffDistance::hausdorffDistancePoints ( const geom::Geometry &  a,
const geom::Geometry &  b 
)
static

Computes a pair of points which attain the symmetric Hausdorff distance between two geometries. This is the maximum of the two directed Hausdorff distances.

Parameters
aa geometry
ba geometry
Returns
a pair of points [ptA, ptB] demonstrating the Hausdorff distance, or empty if an input is empty

◆ isFullyWithinDistance() [1/4]

static bool geos::algorithm::distance::DirectedHausdorffDistance::isFullyWithinDistance ( const geom::Geometry &  a,
const geom::Geometry &  b,
double  maxDistance 
)
static

Computes whether a query geometry lies fully within a given distance of a target geometry. Equivalently, detects whether any point of the query geometry is farther from the target than the specified distance. This is the case if DHD(A, B) > maxDistance.

Parameters
athe query geometry
bthe target geometry
maxDistancethe distance limit
Returns
true if the query geometry lies fully within the distance of the target

◆ isFullyWithinDistance() [2/4]

static bool geos::algorithm::distance::DirectedHausdorffDistance::isFullyWithinDistance ( const geom::Geometry &  a,
const geom::Geometry &  b,
double  maxDistance,
double  tolerance 
)
static

Computes whether a query geometry lies fully within a given distance of a target geometry, up to a given distance accuracy. Equivalently, detects whether any point of the query geometry is farther from the target than the specified distance. This is the case if DHD(A, B) > maxDistance.

Parameters
athe query geometry
bthe target geometry
maxDistancethe distance limit
tolerancethe accuracy distance tolerance
Returns
true if the query geometry lies fully within the distance of the target

◆ isFullyWithinDistance() [3/4]

bool geos::algorithm::distance::DirectedHausdorffDistance::isFullyWithinDistance ( const geom::Geometry &  geom,
double  maxDistance 
) const

Tests whether a query geometry lies fully within a given distance of the target geometry. Equivalently, detects whether any point of the query geometry is farther from the target than the specified distance. This is the case if DHD(A, B) > maxDistance.

Parameters
geomthe query geometry
maxDistancethe distance limit
Returns
true if the query geometry lies fully within the distance of the target

◆ isFullyWithinDistance() [4/4]

bool geos::algorithm::distance::DirectedHausdorffDistance::isFullyWithinDistance ( const geom::Geometry &  geom,
double  maxDistance,
double  tolerance 
) const

Tests whether a query geometry lies fully within a given distance of the target geometry, up to a given distance accuracy. Equivalently, detects whether any point of the query geometry is farther from the target than the specified distance. This is the case if DHD(A, B) > maxDistance.

Parameters
geomthe query geometry
maxDistancethe distance limit
tolerancethe accuracy distance tolerance
Returns
true if the query geometry lies fully within the distance of the target

The documentation for this class was generated from the following file: