This topic describes the ST_MaxDistance function. This function calculates the farthest distance between two geometry objects. The farthest distance is measured in the unit that is specified in the spatial reference system of the geometry objects.

Syntax

float  ST_MaxDistance(geometry  g1 , geometry  g2);

Parameters

Parameter Description
g1 The first geometry object that you want to specify.
g2 The second geometry object that you want to specify.

Description

If the first geometry object and second geometry object that you specify are the same, the function returns the distance between the farthest two vertices of the geometry object.

Examples

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