All Products
Search
Document Center

ApsaraDB RDS:ST_MaxDistance

Last Updated:Mar 28, 2026

Returns the farthest distance between two geometry objects, measured in the units of their spatial reference system (SRS).

Syntax

float ST_MaxDistance(geometry g1, geometry g2)

Parameters

ParameterDescription
g1The first geometry object.
g2The second geometry object.

Usage notes

If g1 and g2 are the same object, the function returns the distance between the two farthest vertices of that object.

Examples

Calculate the farthest distance between two line strings:

SELECT ST_MaxDistance('LINESTRING (0 0,-1 1)'::geometry, 'LINESTRING (0 0,1 1)'::geometry);
 st_maxdistance
----------------
              2
(1 row)