Description
The ST_Distance
function calculates and returns the distance between two
geometries.
Syntax
ST_Distance(WritableGeometry geometry1, WritableGeometry geometry2, String linearUnits, [String computationType])
Parameters
Parameter |
Type |
Description |
geometry1
|
WritableGeometry |
The first instance of a WritableGeometry. |
geometry2
|
WritableGeometry |
The second instance of a WritableGeometry. |
linearUnits
|
String |
The desired return unit type. For valid values, see Linear Units. |
computationType
|
String |
Optional. Indicates the logic to be used to interpret geometry coordinates. The
computation type is based on the coordinate system of the geometry being operated
on:
- For geographic (long/lat) coordinate systems: Valid type =
SPHERICAL (default)
- For projected coordinate systems: Valid types =
CARTESIAN ,
SPHERICAL (default)
- For engineering coordinate systems: Valid type =
CARTESIAN
(default)
- CARTESIAN
- The geometry coordinates are interpreted using cartesian logic.
- SPHERICAL
- The geometry coordinates are interpreted using spherical logic.
|
Linear Units
The following table lists the valid values for unit type.
Value |
Description |
mi |
miles |
km |
kilometers |
in |
inches |
ft |
feet |
yd |
yards |
mm |
millimeters |
cm |
centimeters |
m |
meters |
survey ft |
US Survey feet |
nmi |
nautical miles |
Return Values
Return Type |
Description |
Double |
The distance between the two geometries. Geometries that intersect are at
distance zero from each other. Distance is always non-negative. |
Examples
SELECT ST_Distance(ST_GeomFromWkt(t.geometry,'epsg:4267'),
ST_GeomFromWkt(t.geometry2,'epsg:4267'), 'm', 'SPHERICAL') FROM table t;
SELECT ST_Distance(ST_GeomFromWkt(t.geometry,'epsg:4267'),
ST_GeomFromWkt(t.geometry2,'epsg:4267'), 'm') FROM table t;