Skip to main content
Returns a discretized (and hence approximate) Hausdorff distance between the given 2 geometries. Optionally, a densityFraction parameter can be specified, which gives more accurate results by densifying segments before computing hausdorff distance between them. Each segment is broken down into equal-length subsegments whose ratio with segment length is closest to the given density fraction. Hence, the lower the densityFrac value, the more accurate is the computed hausdorff distance, and the more time it takes to compute it. If any of the geometry is empty, 0.0 is returned.
Accepted range of densityFrac is (0.0, 1.0], if any other value is provided, ST_HausdorffDistance throws an IllegalArgumentException
Even though the function accepts 3D geometry, the z ordinate is ignored and the computed hausdorff distance is equivalent to the geometries not having the z ordinate.
ST_HausdorffDistance

Signatures

ST_HausdorffDistance(g1: Geometry, g2: Geometry, densityFrac: Double)

Parameters

g1
Geometry
required
The g1 value.
g2
Geometry
required
The g2 value.
densityFrac
Double
required
The density frac value.

Return type

A numeric value.

Examples

SELECT ST_HausdorffDistance(ST_GeomFromWKT('POINT (0.0 1.0)'), ST_GeomFromWKT('LINESTRING (0 0, 1 0, 2 0, 3 0, 4 0, 5 0)'), 0.1)
5.0990195135927845
SELECT ST_HausdorffDistance(ST_GeomFromText('POLYGON Z((1 0 1, 1 1 2, 2 1 5, 2 0 1, 1 0 1))'), ST_GeomFromText('POLYGON Z((4 0 4, 6 1 4, 6 4 9, 6 1 3, 4 0 4))'))
5.0