ST_Distance()¶
Returns the minimum distance between two geometries, in Cartesian units or geodesic meters.
Syntax¶
ST_Distance(geom1, geom2)
ST_Distance(geom1, geom2, srid)
Aliases: none.
Arguments¶
geom1 and geom2 are both GEOMETRY or both GEOMETRY32; srid is an INT64 computation override.
Return Value¶
Returns FLOAT64 for GEOMETRY inputs and FLOAT32 for GEOMETRY32 inputs.
Usage Notes¶
Without an override, both geometries must have the same SRID. SRID 4326 returns meters; other supported SRIDs return Cartesian units.
The optional SRID overrides the operand SRIDs and is range-checked.
Examples¶
DROP DATABASE IF EXISTS geo_distance_demo;
CREATE DATABASE geo_distance_demo;
USE geo_distance_demo;
SELECT ST_Distance(ST_GeomFromText('POINT(0 0)'), ST_GeomFromText('POINT(3 4)')) AS cartesian_distance,
ST_Distance(ST_GeomFromText('POINT(0 0)'), ST_GeomFromText('POINT(1 0)'), 4326) AS geodesic_meters;
DROP DATABASE geo_distance_demo;
See Also¶
ST_Distance_Sphere(), ST_Length().