ST_Distance — Returns the shortest distance between two geometries.
double ST_Distance(
bytea GeomA, bytea GeomB)
;
Returns the shortest distance between two geometries. It is calculated in 2d. The resulting distance will be in the units of the incoming geometries.
This function supports GeometryCollections |
2D | 3D | M |
---|---|---|
OGC SFS for SQL. 1.1 (1999) | OGC SFS for SQL. 1.1.0 (2005) | OGC SFS for SQL. 1.2.0 (2006) | SQL-MM Part 3 |
---|---|---|---|
2.1.1.3 | 7.2.20.1 | 7.2.8.1 | 5.1.23 |
SELECT ST_Distance(ga,gb) from (SELECT ST_GeomFromText('POINT(5 4 2 8)') as ga, ST_GeomFromText('POINT(8 6 10 2)') as gb) as foo; --Result 3.605551275463989 SELECT ST_Distance(ga,gb) from (SELECT ST_GeomFromText('POLYGON ((10 30, 0 10, 30 20, 30 30, 20 40, 10 30))') as ga, ST_GeomFromText('GEOMETRYCOLLECTION (POINT (40 30), LINESTRING (50 40, 70 20, 70 10, 70 10, 70 10))') as gb) as foo; --Result 10.0 --Distance Barcelona-Paris degrees SELECT ST_Distance(Barcelona,Paris) as Dist_degrees from (SELECT ST_GeomFromText('POINT(2.183333 41.383333)',4326) as Barcelona, ST_GeomFromText('POINT(2.350833 48.856667)',4326) as Paris) as foo; dist_degrees ------------------ 7.47521085492282 --Distance Barcelona-Paris meters (SRID 25831 UTM ETRS89 H31) SELECT ST_Distance(ST_Transform(Barcelona,25831),ST_Transform(Paris,25831)) as Dist_UTM from (SELECT ST_GeomFromText('POINT(2.183333 41.383333)',4326) as Barcelona, ST_GeomFromText('POINT(2.350833 48.856667)',4326) as Paris) as foo; dist_utm ------------------ 830348.883136392