Skip to content

ST_MaxDistance

Returns the maximum distance between any pair of points in two geometries or geographies.

Usage

double ST_MaxDistance(geomA: geometry, geomB: geometry)
double ST_MaxDistance(geogA: geography, geogB: geography)

Arguments

  • geogA (geography): Input geography
  • geogB (geography): Input geography
  • geomA (geometry): Input geometry
  • geomB (geometry): Input geometry

Description

For geometry, returns the 2D Cartesian maximum distance between any pair of vertices across the two geometries, in the units of the coordinate reference system. For geography, returns the maximum distance in meters calculated using a spherical approximation.

Examples

SELECT ST_MaxDistance(
    ST_GeomFromText('POINT (0 0)'),
    ST_GeomFromText('LINESTRING (3 0, 0 4)')
);
┌──────────────────────────────────────────────────────────────────────────────┐
│ st_maxdistance(st_geomfromtext(Utf8("POINT (0 0)")),st_geomfromtext(Utf8("LI │
│                           NESTRING (3 0, 0 4)")))…                           │
╞══════════════════════════════════════════════════════════════════════════════╡
│                                                                          4.0 │
└──────────────────────────────────────────────────────────────────────────────┘
SELECT ST_MaxDistance(
    ST_GeogFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))'),
    ST_GeogFromText('POLYGON ((10 10, 11 10, 10 11, 10 10))')
);
┌──────────────────────────────────────────────────────────────────────────────┐
│ st_maxdistance(st_geogfromtext(Utf8("POLYGON ((0 0, 1 0, 0 1, 0 0))")),st_ge │
│         ogfromtext(Utf8("POLYGON ((10 10, 11 10, 10 11, 10 10))")))…         │
╞══════════════════════════════════════════════════════════════════════════════╡
│                                                           1648412.0099053395 │
└──────────────────────────────────────────────────────────────────────────────┘