ST_Distance

Determine the minimum distance between two geometries.

Syntax

ST_Distance(geo1, geo2[, unit/varname>[, intersectTest]]);
geo1
The first input point or segment.

Type: ST_GEOMETRY(ANY)

geo2
The second input point or segment.

Type: ST_GEOMETRY(ANY)

unit
The units of the distance. Possible values include 'meter', 'kilometer', 'foot', 'mile', and "nautical mile'.

Type: VARCHAR(ANY)

Default: 'meter'

intersectTest
If set to TRUE, test for intersection between the input geometries and return 0 if they do. Otherwise, calculate the distance between the geometries.

Type: BOOL

Default: TRUE

Returns

A value of type DOUBLE indicating the minimum distance between two the two input points or segments.

Examples

SELECT inza..ST_Distance(inza..ST_Point(0, 0, 27700), inza..ST_Point(1, 0, 27700));

ST_DISTANCE
-------------
1
(1 row)


SELECT inza..ST_Distance(inza..ST_Point(0, 0, 27700),inza..ST_Point(1, 0, 27700), 'foot');

ST_DISTANCE
-----------------
3.2808398950131
(1 row)


SELECT inza..ST_Distance(inza..ST_Transform(inza..ST_Point(0, 0,27700), 4326), inza..ST_Transform(inza..ST_Point(1, 0, 27700), 4326), 'meter');

ST_DISTANCE
------------------
0.99836324443601
(1 row)