This topic describes the ST_HausdorffDistance function. This function calculates the Hausdorff distance between two geometry objects.

Syntax

float  ST_HausdorffDistance(geometry  g1 , geometry  g2);
float  ST_HausdorffDistance(geometry  g1 , geometry  g2 , float  densifyFrac);

Parameters

Parameter Description
g1 The first geometry object that you want to specify.
g2 The second geometry object that you want to specify.
densifyFrac The fraction based on which this function densifies each segment. Each segment is split into a number of equal-length sub-segments, whose fraction of the total length is the closest to the specified fraction.

Description

  • This function supports only vertices as discrete locations and does not limit the number of points.
  • The Hausdorff distance that is returned by this function is not a standard Hausdorff distance. This function returns an approximate distance for large GeometryCollection objects.
  • This function can compute the Hausdorff distance between two LineString objects, which must basically be parallel and have the same length. This function can be used to measure the similarity between LineString objects.

Examples

Calculate the Hausdorff distance between two geometry objects by using the default parameter settings.
SELECT st_hausdorffdistance('LINESTRING (1 0,2 0)'::geometry, 'LINESTRING (-1 0,0 0)'::geometry);
 st_hausdorffdistance
----------------------
                    2
(1 row)