ST_HausdorffDistance
What is ST_HausdorffDistance?
ST_HausdorffDistance returns the discrete Hausdorff distance between two geometries — the greatest of all the minimum distances from each point in one geometry to the nearest point in the other. It is a measure of how far two shapes deviate from each other, independent of point ordering.
1ST_HausdorffDistance(geometry g1, geometry g2) → float
2ST_HausdorffDistance(geometry g1, geometry g2, float densifyFrac) → floatThe optional densifyFrac (between 0 and 1) subdivides segments before measurement, giving a closer approximation to the continuous Hausdorff distance at higher cost. Units are those of the input CRS.
When would you use ST_HausdorffDistance?
Use ST_HausdorffDistance to compare shape similarity where point ordering does not matter — checking how well a simplified polygon approximates the original, auditing the difference between a digitised boundary and a reference boundary, or matching footprints regardless of winding direction. It is widely used in cartographic generalisation QA and in comparing outputs of competing geocoding or boundary-extraction pipelines.
1-- Flag simplified polygons that differ too much from the original
2SELECT id, ST_HausdorffDistance(original_geom, simplified_geom, 0.001) AS hausdorff_m
3FROM parcels
4WHERE ST_HausdorffDistance(original_geom, simplified_geom, 0.001) > 5;FAQs
How is Hausdorff different from Frechet distance?
Hausdorff is order-independent — it cares only about the sets of points. Frechet respects ordering. For comparing a GPS track to a planned route in time order, use Frechet; for comparing two polygon boundaries, use Hausdorff.
What units is the result in?
The units of the input CRS — degrees for EPSG:4326, metres for most projected CRSs. For accurate real-world distances on lat/lon data, reproject first. There is no geography overload.
Why do I sometimes get a smaller value than expected?
The function is discrete by default — it only considers vertices, not points between them. Passing densifyFrac (e.g. 0.01) approximates the continuous Hausdorff distance, which can be larger.
How expensive is ST_HausdorffDistance?
Cost is roughly O(n·m) where n and m are vertex counts. Densification multiplies this. On heavy datasets, pre-simplify with ST_Simplify if you can tolerate the accuracy trade-off, or restrict the query to candidate pairs using an ST_DWithin filter first.