# ST_FrechetDistance

## Name

ST_FrechetDistance — Returns the Fréchet distance between two geometries.

## Synopsis

```
float
```

geometry
**
ST_FrechetDistance
**
(
`
g1
`
, geometry
`
g2
`
, float
`
densifyFrac = -1
`
```
)
```

;

## Description

Implements algorithm for computing the Fréchet distance restricted to discrete points for both geometries, based on Computing Discrete Fréchet Distance . The Fréchet distance is a measure of similarity between curves that takes into account the location and ordering of the points along the curves. Therefore it is often better than the Hausdorff distance.

When the optional densifyFrac is specified, this function performs a segment densification before computing the discrete Fréchet distance. The densifyFrac parameter sets the fraction by which to densify each segment. Each segment will be split into a number of equal-length subsegments, whose fraction of the total length is closest to the given fraction.

Units are in the units of the spatial reference system of the geometries.

The current implementation supports only vertices as the discrete locations. This could be extended to allow an arbitrary density of points to be used. |

The smaller densifyFrac we specify, the more acurate Fréchet distance we get. But, the computation time and the memory usage increase with the square of the number of subsegments. |

Performed by the GEOS module.

Availability: 2.4.0 - requires GEOS >= 3.7.0

## Examples

postgres=# SELECT st_frechetdistance('LINESTRING (0 0, 100 0)'::geometry, 'LINESTRING (0 0, 50 50, 100 0)'::geometry); st_frechetdistance -------------------- 70.7106781186548 (1 row)

SELECT st_frechetdistance('LINESTRING (0 0, 100 0)'::geometry, 'LINESTRING (0 0, 50 50, 100 0)'::geometry, 0.5); st_frechetdistance -------------------- 50 (1 row)