> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wherobots.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ST_HausdorffDistance

Returns a discretized (and hence approximate) [Hausdorff distance](https://en.wikipedia.org/wiki/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.

<Note>
  Accepted range of densityFrac is (0.0, 1.0], if any other value is provided, ST\_HausdorffDistance throws an IllegalArgumentException
</Note>

<Note>
  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.
</Note>

<img src="https://mintcdn.com/wherobots/fqh3gPDE0J25Lra_/images/sql-functions/ST_HausdorffDistance/ST_HausdorffDistance.svg?fit=max&auto=format&n=fqh3gPDE0J25Lra_&q=85&s=d685f34e6a85b523c153765cf988a19e" alt="ST_HausdorffDistance" width="500" height="300" data-path="images/sql-functions/ST_HausdorffDistance/ST_HausdorffDistance.svg" />

## Signatures

```sql theme={"system"}
ST_HausdorffDistance(g1: Geometry, g2: Geometry, densityFrac: Double)
```

## Parameters

<ParamField body="g1" type="Geometry" required>
  The g1 value.
</ParamField>

<ParamField body="g2" type="Geometry" required>
  The g2 value.
</ParamField>

<ParamField body="densityFrac" type="Double" required>
  The density frac value.
</ParamField>

## Return type

<ResponseField type="Double">
  A numeric value.
</ResponseField>

## Examples

```sql theme={"system"}
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
```

```sql theme={"system"}
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
```
