ST_MaxDistance
Name
ST_MaxDistance — Returns the 2D largest distance between two geometries in projected units.
Synopsis
float
ST_MaxDistance
(
geometry
g1
, geometry
g2
)
;
Description
Returns the 2-dimensional maximum distance between two geometries, in projected units. The maximum distance always occurs between two vertices. This is the length of the line returned by ST_LongestLine .
If g1 and g2 are the same geometry, returns the distance between the two vertices farthest apart in that geometry.
Availability: 1.5.0
Examples
Maximum distance between a point and lines.
postgis=# SELECT ST_MaxDistance('POINT(0 0)'::geometry, 'LINESTRING ( 2 0, 0 2 )'::geometry); st_maxdistance ----------------- 2 postgis=# SELECT ST_MaxDistance('POINT(0 0)'::geometry, 'LINESTRING ( 2 2, 2 2 )'::geometry); st_maxdistance ------------------ 2.82842712474619
Maximum distance between vertices of a geometry.
SELECT ST_MaxDistance('POLYGON ((10 10, 10 0, 0 0, 10 10))'::geometry, 'POLYGON ((10 10, 10 0, 0 0, 10 10))'::geometry); st_maxdistance ------------------ 14.142135623730951