ST_Distance function
The ST_Distance function takes two geometries and, optionally, a unit as input parameters and returns the shortest distance between any point in the first geometry to any point in the second geometry, measured in the default or given units.
If any of the two geometries is null or is empty, null is returned.
If the second geometry is not represented in the same spatial reference system as the first geometry and uses the same underlying datum, it will be converted to the other spatial reference system.
You can also call this function as a method when you provide a unit of measure.
Syntax
Parameter
- geometry1
- A value of type ST_Geometry that represents the geometry that is used to compute the distance to geometry2.
- geometry2
- A value of type ST_Geometry that represents the geometry that is used to compute the distance to geometry1.
- unit
- VARCHAR(128) value that identifies the unit in which the result is measured. The supported units of measure are listed in the DB2GSE.ST_UNITS_OF_MEASURE catalog view.
- intersectsTest
- Set this flag to 1 to check whether geometry1 and geometry2 intersect instead of calculating the distance. When intersectsTest is specified, the function returns 1 if the geometries intersect and 0 if they do not.
If the unit parameter is omitted, the following
rules are used to determine the unit of measure used for the result:
- If geometry1 is in a projected or geocentric coordinate system, the linear unit associated with this coordinate system is the default.
- If geometry1 is in a geographic coordinate system, the angular unit associated with this coordinate system is the default.
Restrictions on unit conversions: An error (SQLSTATE
38SU4) is returned if any of the following conditions occur:
- The geometry is in an unspecified coordinate system and the unit parameter is specified.
- The geometry is in a projected coordinate system and an angular unit is specified.
Return type
DOUBLE