ST_MaxDistance
Signature
DOUBLE ST_MaxDistance(GEOMETRY geomA, GEOMETRY geomB);
Description
Returns the 2-dimensional longest distance between the points of two geometries (geomA
and geomB
).
If geomA
and geomB
are the same, the function will return the longest distance between the two farthest vertices in this geometry.
Distance is measured in the units of the spatial reference system.
Remark
To return the geometry (LINESTRING
) that correspond to the longest distance, the user may use ST_LongestLine
.
Examples
Cases where geomA
and geomB
are different
SELECT ST_MaxDistance('POLYGON ((0 1, 1 1, 1 0, 0 0, 0 1))',
'POLYGON ((2 3, 2 2, 3 2, 4 3, 2 3))');
-- Answer: 5
SELECT ST_MaxDistance('POLYGON ((0 1, 1 1, 1 0, 0 0, 0 1))',
'LINESTRING (1 3, 4 3)');
-- Answer: 5
SELECT ST_MaxDistance('POLYGON ((0 1, 1 1, 1 0, 0 0, 0 1))',
'POINT (3 2)');
-- Answer: 3,605551275463989
SELECT ST_MaxDistance('MULTIPOLYGON (((0 1, 1 1, 1 0, 0 0, 0 1)),
((2 3, 2 2, 3 3, 2 3)))',
'POINT (3 2)');
-- Answer: 3,605551275463989
Case where geomA
is equal to geomB
SELECT ST_MaxDistance('POLYGON ((1 3, 0 0, 3 2, 1 3))',
'POLYGON ((1 3, 0 0, 3 2, 1 3))');
-- Answer: 3,605551275463989