Spatial functions

Updated at:

Function

Features

ST_AREA

Calculates the area of a geometry.

ST_CONTAINS

Checks if one geometry contains another.

ST_COVERS

Checks if one geometry covers another.

ST_CROSSES

Checks if two geometries cross.

ST_DIFFERENCE

Calculates the difference between two geometries.

ST_DISTANCE

Calculates the distance between two geometries.

ST_EQUALS

Checks if two geometries are equal.

ST_GEOM_FROM_TEXT

Creates a geometry object from a Well-Known Text (WKT) string.

ST_INTERSECTION

Calculates the intersection of two geometries.

ST_INTERSECTS

Checks if two geometries intersect.

ST_LENGTH

Calculates the 2D length of a line geometry.

ST_OVERLAPS

Checks if two geometries overlap.

ST_TOUCHES

Checks if two geometries touch.

ST_TRANSFORM

Transforms the coordinate system of a geometry.

ST_WITHIN

Checks if a geometry is within another.

ST_AREA

  • Description

Returns the area of a polygon geometry object. The 2D Cartesian area is calculated in the units specified by the object's Spatial Reference System Identifier (SRID).

  • Parameters

    • geometry: Required. The geometry object. The type is geometry.

  • Return value

The area of the geometry object.

  • Supported computing engines

AnalyticDB for PostgreSQL (ADB_PG), POLARDB for PostgreSQL (POLAR_PG), and PostgreSQL.

ST_CONTAINS

  • Description

Returns true if geometry A contains geometry B. This condition is met if and only if no points of geometry B lie in the exterior of geometry A, and at least one point of the interior of geometry B lies in the interior of geometry A.

  • Parameters

    • geometryA: Required. Geometry A. The type is geometry.

    • geometryB: Required. Geometry B. The type is geometry.

  • Return value

A boolean value indicating whether geometry A contains geometry B.

  • Supported computing engines

ADB_PG, POLAR_PG, and PostgreSQL.

ST_COVERS

  • Description

Returns true if geometry A covers geometry B. This occurs when no point of geometry B is outside geometry A.

  • Parameters

    • geometryA: Required. Geometry A. The type is geometry.

    • geometryB: Required. Geometry B. The type is geometry.

  • Return value

A boolean value indicating whether geometry A covers geometry B.

  • Supported computing engines

ADB_PG, POLAR_PG, and PostgreSQL.

ST_CROSSES

  • Description

Returns true if two geometries cross. Geometries cross if they have a partial intersection and neither contains the other.

  • Parameters

    • geometryA: Required. Geometry A. The type is geometry.

    • geometryB: Required. Geometry B. The type is geometry.

  • Return value

A boolean value indicating whether geometry A and geometry B cross.

  • Supported computing engines

ADB_PG, POLAR_PG, and PostgreSQL.

ST_DIFFERENCE

  • Description

Returns a geometry object that represents the part of geometry A that does not intersect with geometry B. If geometry A is completely inside geometry B, the function returns an empty geometry object.

  • Parameters

    • geometryA: Required. Geometry A. The type is geometry.

    • geometryB: Required. Geometry B. The type is geometry.

  • Return value

A geometry object representing the difference between geometry A and geometry B.

  • Supported computing engines

ADB_PG, POLAR_PG, and PostgreSQL.

ST_DISTANCE

  • Description

Returns the Euclidean distance between two geometry objects. The distance is calculated in the units of their coordinate system.

  • Parameters

    • geometryA: Required. Geometry A. The type is geometry.

    • geometryB: Required. Geometry B. The type is geometry.

  • Return value

The Euclidean distance between geometry A and geometry B.

  • Supported computing engines

ADB_PG, POLAR_PG, and PostgreSQL.

ST_EQUALS

  • Description

Returns true if two geometry objects are spatially equal.

  • Parameters

    • geometryA: Required. Geometry A. The type is geometry.

    • geometryB: Required. Geometry B. The type is geometry.

  • Return value

A boolean value indicating whether geometry A and geometry B are spatially equal.

  • Supported computing engines

ADB_PG, POLAR_PG, and PostgreSQL.

ST_GEOM_FROM_TEXT

  • Description

Returns a geometry object from a Well-Known Text (WKT) representation.

  • Parameters

    • wkt: Required. The WKT string. The type is string.

    • srid: Optional. The SRID of the geometry object. The type is integer.

  • Return value

The geometry object corresponding to the WKT string.

  • Supported computing engines

ADB_PG, POLAR_PG, and PostgreSQL.

ST_INTERSECTION

  • Description

Returns a geometry object that represents the intersection of two geometry objects. If the objects do not intersect, the function returns an empty geometry object. Note: This function discards the M coordinate values of the objects.

  • Parameters

    • geometryA: Required. Geometry A. The type is geometry.

    • geometryB: Required. Geometry B. The type is geometry.

  • Return value

A geometry object representing the intersection of geometry A and geometry B.

  • Supported computing engines

ADB_PG, POLAR_PG, and PostgreSQL.

ST_INTERSECTS

  • Description

Returns true if two geometry objects intersect. Two geometry objects intersect if they have any point in common.

  • Parameters

    • geometryA: Required. Geometry A. The type is geometry.

    • geometryB: Required. Geometry B. The type is geometry.

  • Return value

A boolean value indicating whether geometry A and geometry B intersect.

  • Supported computing engines

ADB_PG, POLAR_PG, and PostgreSQL.

ST_LENGTH

  • Description

Returns the 2D Cartesian length of a linestring geometry object. The unit of length is specified by the object's coordinate system. If the geometry object is a polygon, the function returns 0.

  • Parameters

    • geometry: Required. The geometry object. The type is geometry.

  • Return value

The length of the geometry object.

  • Supported computing engines

ADB_PG, POLAR_PG, and PostgreSQL.

ST_OVERLAPS

  • Description

Returns true if two geometry objects spatially overlap but neither one completely contains the other.

  • Parameters

    • geometryA: Required. Geometry A. The type is geometry.

    • geometryB: Required. Geometry B. The type is geometry.

  • Return value

A boolean value indicating whether geometry A and geometry B overlap.

  • Supported computing engines

ADB_PG, POLAR_PG, and PostgreSQL.

ST_TOUCHES

  • Description

Returns true if two geometry objects touch but their interiors do not intersect. Two geometry objects touch if they have at least one point in common and the common points lie on at least one boundary. For a point/point input, the function returns false because points do not have boundaries.

  • Parameters

    • geometryA: Required. Geometry A. The type is geometry.

    • geometryB: Required. Geometry B. The type is geometry.

  • Return value

The result indicates whether Geometry A and Geometry B overlap.

  • Supported computing engines

ADB_PG, POLAR_PG, and PostgreSQL.

ST_TRANSFORM

  • Description

Returns a new geometry object with its coordinates transformed to a different coordinate system.

  • Parameters

    • geometry: Required. The geometry object. The type is geometry.

    • srid: Required. The SRID of the target coordinate system. The type is integer.

  • Return value

The transformed geometry object.

  • Supported computing engines

ADB_PG, POLAR_PG, and PostgreSQL.

ST_WITHIN

  • Description

Returns true if geometry A is completely within geometry B.

  • Parameters

    • geometryA: Required. Geometry A. The type is geometry.

    • geometryB: Required. Geometry B. The type is geometry.

  • Return value

A boolean value indicating whether geometry A is within geometry B.

  • Supported computing engines

ADB_PG, POLAR_PG, and PostgreSQL.