Help Center > > Developer Guide> Geometry Query> Support of Geometry Query Functions> Spatial Relationships

# Spatial Relationships

Updated at: Apr 09, 2019 GMT+08:00

#### st_area

`Double st_area(Geometry g)`

If Geometry g is areal, this function returns the area of its surface in square units of the coordinate reference system (for example, degrees^2 for EPSG:4326). This function returns 0.0 for non-areal geometries (for example, Points and non-closed LineStrings).

Example:

• Query command:

select st_area(st_geomFromWKT(location)) from geotbl where id='1'

• The query result is as follows:
`550.0`

#### st_centroid

`Point st_centroid(Geometry g)`

This function returns the geometric center of a geometry.

Example:

• Query command:

select st_asText(st_centroid(st_geomFromWKT(location))) from geotbl where id='4'

• The query result is as follows:
`POINT (27.40740740740741 28.765432098765434)`

#### st_closestPoint

`Point st_closestPoint(Geometry a, Geometry b)`

This function returns the Point on a that is closest to b. This is the first point of the shortest line.

Example:

• Query command:

select st_asText(st_closestPoint((select st_geomFromWKT(location) from geotbl where id='1'),(select st_geomFromWKT(location) from geotbl where id='2')))

• The query result is as follows:
`POINT (40 40)`

#### st_contains

`Boolean st_contains(Geometry a, Geometry b)`

This function returns true if and only if no points of b lie in the exterior of a, and at least one point of the interior of b lies in the interior of a.

Example:

• Query command:

select st_contains((select st_geomFromWKT(location) from geotbl where id='1'),(select st_geomFromWKT(location) from geotbl where id='2'))

• The query result is as follows:
`FALSE`

#### st_covers

`Boolean st_covers(Geometry a, Geometry b)`

This function returns true if no point in Geometry b is outside Geometry a.

Example:

• Query command:

select st_covers((select st_geomFromWKT(location) from geotbl where id='1'),(select st_geomFromWKT(location) from geotbl where id='2'))

• The query result is as follows:
`FALSE`

#### st_crosses

`Boolean st_crosses(Geometry a, Geometry b)`

This function returns true if the supplied geometries have some, but not all, interior points in common.

Example:

• Query command:

select st_crosses((select st_geomFromWKT(location) from geotbl where id='1'),(select st_geomFromWKT(location) from geotbl where id='2'))

• The query result is as follows:
`FALSE`

#### st_disjoint

`Boolean st_disjoint(Geometry a, Geometry b)`

This function returns true if the geometries do not spatially intersect, for example, they do not share any space together. This function is equivalent to NOT st_intersects(a, b).

Example:

• Query command:

select st_disjoint((select st_geomFromWKT(location) from geotbl where id='1'),(select st_geomFromWKT(location) from geotbl where id='2'))

• The query result is as follows:
`TRUE`

#### st_distance

`Double st_distance(Geometry a, Geometry b)`

This function returns the 2D Cartesian distance between the two geometries in units of the coordinate reference system (for example, degrees for EPSG:4236).

Example:

• Query command:

select st_distance((select st_geomFromWKT(location) from geotbl where id='1'),(select st_geomFromWKT(location) from geotbl where id='2'))

• The query result is as follows:
`25.4950975679639`

#### st_distanceSphere

`Double st_distanceSphere(Geometry a, Geometry b)`

This function approximates the minimum distance between two longitude/latitude geometries assuming a spherical earth.

Example:

• Query command:

select st_distanceSphere((select st_geomFromWKT(location) from geotbl where id='1'),(select st_geomFromWKT(location) from geotbl where id='2'))

• The query result is as follows:
`3284010.93490738`

#### st_distanceSpheroid

`Double st_distanceSpheroid(Geometry a, Geometry b)`

This function returns the minimum distance between two longitude/latitude geometries assuming the WGS84 spheroid.

Example:

• Query command:

select st_distanceSpheroid((select st_geomFromWKT(location) from geotbl where id='1'),(select st_geomFromWKT(location) from geotbl where id='2'))

• The query result is as follows:
`3288016.93279476`

#### st_equals

`Boolean st_equals(Geometry a, Geometry b)`

This function returns true if the given Geometries represent the same logical Geometry. Directionality is ignored.

Example:

• Query command:

select st_equals((select st_geomFromWKT(location) from geotbl where id='1'),(select st_geomFromWKT(location) from geotbl where id='2'))

• The query result is as follows:
`FALSE`

#### st_intersects

`Boolean st_intersects(Geometry a, Geometry b)`

This function returns true if the geometries spatially intersect in 2D (for example, share any portion of space). This function is equivalent to NOT st_disjoint(a, b).

Example:

• Query command:

select st_intersects((select st_geomFromWKT(location) from geotbl where id='1'),(select st_geomFromWKT(location) from geotbl where id='2'))

• The query result is as follows:
`FALSE`

#### st_length

`Double st_length(Geometry geom)`

This function returns the 2D path length of linear geometries, or perimeter of areal geometries, in units of the coordinate reference system (for example, degrees for EPSG:4236). It returns 0.0 for other geometry types (for example, Point).

Example:

• Query command:

select st_length(st_geomFromWKT(location)) from geotbl where id='4'

• The query result is as follows:
`160.12062648706927`

#### st_lengthSphere

`Double st_lengthSphere(LineString line)`

This function approximates the 2D path length of a LineString geometry using a spherical earth model. The returned length is in units of meters. The approximation is within 0.3% of st_lengthSpheroid and is computationally more efficient.

Example:

• Query command:

select st_lengthSphere(st_castToLineString(st_geomFromWKT(location))) from geotbl where id='5'

• The query result is as follows:
`1.0013773137296816E7`

#### st_lengthSpheroid

`Double st_lengthSpheroid(LineString line)`

This function calculates the 2D path length of a LineString geometry defined with longitude/latitude coordinates on the WGS84 spheroid. The returned length is in units of meters.

Example:

• Query command:

select st_lengthSpheroid(st_castToLineString(st_geomFromWKT(location))) from geotbl where id='5'

• The query result is as follows:
`1.0001465052274073E7`

#### st_overlaps

`Boolean st_overlaps(Geometry a, Geometry b)`

This function returns true if the geometries have some but not all points in common, are of the same dimension, and the intersection of the interiors of the two geometries has the same dimension as the geometries themselves.

Example:

• Query command:

select st_overlaps((select st_geomFromWKT(location) from geotbl where id='1'),(select st_geomFromWKT(location) from geotbl where id='2'))

• The query result is as follows:
`FALSE`

#### st_relate

`String st_relate(Geometry a, Geometry b)`

This function returns the DE-9IM 3x3 interaction matrix pattern describing the dimensionality of the intersections between the interior, boundary and exterior of the two geometries.

Example:

• Query command:

select st_relate((select st_geomFromWKT(location) from geotbl where id='1'),(select st_geomFromWKT(location) from geotbl where id='2'))

• The query result is as follows:
`FF2FF1212`

#### st_relateBool

`Boolean st_relateBool(Geometry a, Geometry b, String mask)`

This function returns true if the DE-9IM interaction matrix mask matches the interaction matrix pattern obtained from st_relate(a, b).

Example:

• Query command:

select st_relateBool((select st_geomFromWKT(location) from geotbl where id='1'),(select st_geomFromWKT(location) from geotbl where id='2'),'FF2FF1212')

• The query result is as follows:
`TRUE`

#### st_touches

`Boolean st_touches(Geometry a, Geometry b)`

This function returns true if the geometries have at least one point in common, but their interiors do not intersect.

Example:

• Query command:

select st_touches((select st_geomFromWKT(location) from geotbl where id='1'),(select st_geomFromWKT(location) from geotbl where id='2'))

• The query result is as follows:
`FALSE`

#### st_within

`Boolean st_within(Geometry a, Geometry b)`

This function returns true if geometry a is completely inside geometry b.

Example:

• Query command:

select st_within((select st_geomFromWKT(location) from geotbl where id='1'),(select st_geomFromWKT(location) from geotbl where id='2'))

• The query result is as follows:
`FALSE`

### Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

### Which of the following issues have you encountered?

Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel