Name

ST_MaxDistance — Returns the 2D largest distance between two geometries in projected units.

Synopsis

float ST_MaxDistance(geometry g1, geometry g2);

Descripción

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.

Disponibilidad: 1.5.0

Ejemplos

Maximum distance between a point and lines.

SELECT ST_MaxDistance('POINT(0 0)'::geometry, 'LINESTRING ( 2 0, 0 2 )'::geometry);
-----------------
 2

SELECT ST_MaxDistance('POINT(0 0)'::geometry, 'LINESTRING ( 2 2, 2 2 )'::geometry);
------------------
 2.82842712474619

Maximum distance between vertices of a single geometry.

SELECT ST_MaxDistance('POLYGON ((10 10, 10 0, 0 0, 10 10))'::geometry,
                      'POLYGON ((10 10, 10 0, 0 0, 10 10))'::geometry);
------------------
 14.142135623730951