All Products
Search
Document Center

Simple Log Service:Geospatial functions

Last Updated:Jun 21, 2026

This topic describes the basic syntax and examples of geospatial functions.

Geospatial concepts

Geospatial functions with the ST_ prefix comply with the SQL/MM standard and the OpenGIS specification from the Open Geospatial Consortium (OGC). These functions use the Well-Known Text (WKT) format to describe geometries, such as points, line strings, and polygons. The following table lists the supported geometries and their WKT formats.

Geometry

WKT format

Point

POINT (0 0)

Line string

LINESTRING (0 0, 1 1, 1 2)

Polygon

POLYGON((0 0, 4 0, 4 4, 0 4, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1))

Multipoint

MULTIPOINT(0 0, 1 2)

Multilinestring

MULTILINESTRING((0 0, 1 1, 1 2), (2 3, 3 2, 5 4))

Multipolygon

MULTIPOLYGON(((0 0, 4 0, 4 4, 0 4, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1)), ((-1 -1, -1 -2, -2 -2, -2 -1, -1 -1)))

Geometry collection

GEOMETRYCOLLECTION(POINT(2 3), LINESTRING(2 3, 3 4))

Functions

Type

Function

Syntax

Description

SQL

SPL

Constructors

ST_AsText function

ST_AsText(x)

Returns the Well-Known Text (WKT) representation of a geometry.

×

ST_GeometryFromText function

ST_GeometryFromText(x)

Constructs a geometry from a WKT representation.

×

ST_LineFromText function

ST_LineFromText(x)

Constructs a line string from a WKT representation.

×

ST_Polygon function

ST_Polygon(x)

Constructs a polygon from a WKT representation.

×

ST_Point function

ST_Point(x, y)

Constructs a point from the X and Y coordinates.

×

Operators

ST_Boundary function

ST_Boundary(x)

Returns the boundary of a geometry.

×

ST_Buffer function

ST_Buffer(x, distance)

Returns a geometry that includes all points within a specified distance of the input geometry.

×

ST_Difference function

ST_Difference(x, y)

Returns the part of the first geometry that does not intersect the second geometry.

×

ST_Envelope function

ST_Envelope(x)

Returns the bounding box of a geometry.

×

ST_ExteriorRing function

ST_ExteriorRing(x)

Returns a line string representing the exterior ring of a polygon.

×

ST_Intersection function

ST_Intersection(x, y)

Returns a geometry that represents the intersection of two geometries.

×

ST_SymDifference function

ST_SymDifference(x, y)

Returns a geometry representing the parts of the input geometries that do not intersect.

×

Spatial relationship tests

ST_Contains function

ST_Contains(x, y)

Returns true if the first geometry contains the second geometry. Their boundaries can intersect.

×

ST_Crosses function

ST_Crosses(x, y)

Returns true if the geometries cross.

×

ST_Disjoint function

ST_Disjoint(x, y)

Returns true if the two geometries do not have any points in common.

×

ST_Equals function

ST_Equals(x, y)

Returns true if the two geometries are identical.

×

ST_Intersects function

ST_Intersects(x, y)

Returns true if the two geometries intersect.

×

ST_Overlaps function

ST_Overlaps(x, y)

Returns true if two geometries overlap. Geometries overlap if they have the same dimension and their intersection results in a geometry of the same dimension, but they are not equal.

×

ST_Relate function

ST_Relate(x, y, patternMatrix string)

Returns true if the two geometries satisfy the specified spatial relationship pattern.

×

ST_Touches function

ST_Touches(x, y)

Returns true if the two geometries touch at their boundaries but their interiors do not intersect.

×

ST_Within function

ST_Within(x, y)

Returns true if the first geometry is completely within the second geometry.

×

Accessors

ST_Area function

ST_Area(x)

Returns the 2D Cartesian area of a geometry.

×

ST_Centroid function

ST_Centroid(x)

Returns the geometric centroid of a geometry.

×

ST_CoordDim function

ST_CoordDim(x)

Returns the coordinate dimension of a geometry.

×

ST_Dimension function

ST_Dimension(x)

Returns the inherent dimension of a geometry, which must be less than or equal to the coordinate dimension.

×

ST_Distance function

ST_Distance(x, y)

Returns the minimum distance between two geometries.

×

ST_EndPoint function

ST_EndPoint(x)

Returns the last point of a line string.

×

ST_IsClosed function

ST_IsClosed(x)

Returns true if the start and end points of a line string are the same.

×

ST_IsEmpty function

ST_IsEmpty(x)

Returns true if the specified geometry is empty.

×

ST_IsRing function

ST_IsRing(x)

Returns true if a line string is closed and simple (a ring).

×

ST_Length function

ST_Length(x)

Returns the 2D Cartesian length of a line string. If the input is a multilinestring, returns the sum of the lengths of its elements.

×

ST_NumPoints function

ST_NumPoints(x)

Returns the number of points (vertices) in a geometry.

×

ST_NumInteriorRing function

ST_NumInteriorRing(x)

Returns the number of interior rings in a polygon.

×

ST_StartPoint function

ST_StartPoint(x)

Returns the first point of a line string.

×

ST_X function

ST_X(x)

Returns the X-coordinate of a point.

×

ST_XMax function

ST_XMax(x)

Returns the maximum X-coordinate of a geometry.

×

ST_XMin function

ST_XMin(x)

Returns the minimum X-coordinate of a geometry.

×

ST_Y function

ST_Y(x)

Returns the Y-coordinate of a point.

×

ST_YMax function

ST_YMax(x)

Returns the maximum Y-coordinate of a geometry.

×

ST_YMin function

ST_YMin(x)

Returns the minimum Y-coordinate of a geometry.

×

Bing tiles

bing_tile function

bing_tile(x, y, zoom_level)

Returns a Bing tile from the specified X and Y coordinates and zoom level.

×

bing_tile(quadKey)

Returns a Bing tile from the specified quadtree key.

×

bing_tile_at function

bing_tile_at(x, y, zoom_level)

Returns a Bing tile from the specified latitude, longitude, and zoom level.

×

bing_tile_coordinates function

bing_tile_coordinates(x)

Returns the X- and Y-coordinates of a Bing tile.

×

bing_tile_polygon function

bing_tile_polygon(x)

Returns the polygon representation of a Bing tile.

×

bing_tile_quadkey function

bing_tile_quadkey(x)

Returns the quadtree key of a Bing tile.

×

bing_tile_zoom_level function

bing_tile_zoom_level(x)

Returns the zoom level of a Bing tile.

×

ST_AsText function

Returns the WKT of a geometry.

Syntax

ST_AsText(x)

Parameters

Parameter

Description

x

The input geometry.

Return value type

The return type is varchar.

Examples

This example returns the WKT of a point.

  • Query statement

    * | SELECT ST_AsText(ST_Point(1,1))
  • The query and analysis result is POINT (1 1).

ST_GeometryFromText function

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

Syntax

ST_GeometryFromText(x)

Parameters

Parameter

Description

x

The parameter must be of type varchar.

Return value type

geometry

Examples

Construct a multipolygon.

  • Query statement

    * | SELECT ST_GeometryFromText('multipolygon(((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 40)))')
  • The query returns MULTIPOLYGON (((10 10, 10 20, 20 20, 20 15, 10 10)), ((50 40, 50 50, 60 50, 60 40, 50 40))).

ST_LineFromText function

Creates a line string from WKT text.

Syntax

ST_LineFromText(x)

Parameters

Parameter

Description

x

A value of the varchar type.

Return value type

linestring type

Examples

Construct a line string.

  • Query statement

    * | SELECT ST_LineFromText('linestring(10 10,20 20)')
  • Query results: LINESTRING (10 10, 20 20).

ST_Polygon function

The ST_Polygon function creates a polygon from a WKT representation.

Syntax

ST_Polygon(x)

Parameters

Parameter

Description

x

Must be a varchar value.

Return value type

polygon

Examples

Creates a polygon.

  • Query and analysis statement

    * | SELECT ST_Polygon('polygon((10 10,10 20,20 20,20 15,10 10))')
  • The result is POLYGON ((10 10, 20 15, 20 20, 10 20, 10 10)).

ST_Point function

Constructs a point from the specified X and Y coordinates.

Syntax

ST_Point(x, y)

Parameters

Parameter

Description

x

The X-coordinate of the point. The data type must be DOUBLE.

y

The Y-coordinate of the point. The data type must be DOUBLE.

Return value type

point

Examples

Construct a point.

  • Query statement

    * | SELECT ST_Point(0,0)
  • The query result is in WKT format: POINT (0 0)

ST_Boundary function

The ST_Boundary function returns the boundary of a geometry.

  • The boundary of a point is empty. The function returns POINT EMPTY.

  • The boundary of a line string consists of its end points.

  • The boundary of a polygon consists of the line strings that form its exterior ring and all its interior rings.

Syntax

ST_Boundary(x)

Parameters

Parameter

Description

x

A value of the geography type.

Return value type

geography type

Examples

Use the ST_Polygon function to construct a polygon, and then return its boundary with the ST_Boundary function.

  • Query statement

    * | SELECT  ST_Boundary(ST_Polygon('polygon((10 10,10 20,20 20,20 15,10 10))'))
  • The query returns LINESTRING (10 10, 20 15, 20 20, 10 20, 10 10).

ST_Buffer function

The ST_Buffer function returns a geometry that encompasses all points within a specified distance from an input geometry.

Syntax

ST_Buffer(x, distance)

Parameters

Parameter

Description

x

The input geometry.

distance

The buffer distance.

Return value type

geometry

Examples

This example uses the ST_Point function to construct a point and the ST_Buffer function to create a polygon at a specified distance from that point.

  • Query statement

    * | SELECT ST_Buffer(ST_Point(1,1),1)
  • The query returns a POLYGON value that approximates a circle. This polygon consists of many coordinate points, starting with (2 1, 1.9978589232386...).

ST_Difference function

Returns a geometry that represents the point-set difference of two geometries.

Syntax

ST_Difference(x, y)

Parameters

Parameter

Description

x

A geometry value.

y

A geometry value.

Return value type

A geometry value.

Examples

Construct two geometries with the ST_GeometryFromText function, and then calculate their point-set difference with the ST_Difference function.

  • Query and analysis statement

    * |
    SELECT
      ST_Difference(
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,0 15,0 10), (50 40,50 50,60 50,60 40,50 40)))'
        ),
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 50)))'
        )
      ) AS "Difference"
  • The query returns the following result: MULTIPOLYGON (((0 10, 10 10, 10 17.5, 0 15, 0 10)), ((50 40, 60 40, 50 50, 50 40))).

ST_Envelope function

Returns the bounding box of a geometry.

Syntax

ST_Envelope(x)

Parameters

Parameter

Description

x

A geometry value.

Return value type

geometry

Examples

This example creates a geometry with the ST_GeometryFromText function and returns its bounding box with the ST_Envelope function.

  • Query and analysis statement

    * |
    SELECT
      ST_Envelope(
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 40)))'
        )
      ) 
  • The query returns POLYGON ((10 10, 60 10, 60 50, 10 50, 10 10)).

ST_ExteriorRing function

Returns the exterior ring of a geometry as a linestring.

Syntax

ST_ExteriorRing(x)

Parameters

Parameter

Description

x

The input polygon or multipolygon geometry.

Return value type

geometry

Examples

This example uses ST_GeometryFromText to construct a geometry and ST_ExteriorRing to return its exterior ring.

  • Query statement

    * |
    SELECT
      ST_ExteriorRing(
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 40)))'
        )
      )
  • The query returns LINESTRING (10 10, 10 20, 20 20, 20 15, 10 10).

ST_Intersection

Returns the intersection of two geometries.

Syntax

ST_Intersection(x, y)

Parameters

Parameter

Description

x

The first geometry.

y

The second geometry.

Return value type

geometry

Examples

This example uses the ST_GeometryFromText function to construct two geometries and the ST_Intersection function to calculate their intersection.

  • Query statement

    * |
    SELECT
      ST_Intersection(
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 40)))'
        ),
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 40)))'
        )
      ) 
  • Query results: MULTIPOLYGON (((10 10, 10 20, 20 20, 20 15, 10 10)), ((50 40, 50 50, 60 50, 60 40, 50 40)))

ST_SymDifference function

Returns a geometry representing the symmetric difference of two geometries.

Syntax

ST_SymDifference(x, y)

Parameters

Parameter

Description

x

A geometry.

y

A geometry.

Return value type

geometry

Examples

This example uses the ST_GeometryFromText function to construct two geometries and the ST_SymDifference function to calculate their symmetric difference.

  • Query statement

    * |
    SELECT
      ST_SymDifference(
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 40)))'
        ),
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 40)))'
        )
      )
  • The query returns GEOMETRYCOLLECTION EMPTY.

ST_Contains function

ST_Contains returns true if the first geometry contains the second. The two geometries can intersect at their boundaries.

Syntax

ST_Contains(x, y)

Parameters

Parameter

Description

x

The first input geometry.

y

The second input geometry.

Return value type

boolean

Examples

This example checks if a polygon contains a point.

  • Query statement

    * |
    SELECT
      ST_Contains(
        ST_GeometryFromText(
          'polygon((10 10,10 20,20 20,20 15,10 10))'
        ),
        ST_GeometryFromText(
          'point(11 11)'
        )
      )
  • The query returns true.

ST_Crosses function

The ST_Crosses function returns true if two geometries have interior points in common.

Syntax

ST_Crosses(x, y)

Parameters

Parameter

Description

x

A geometry value.

y

A geometry value.

Return value type

A boolean value.

Examples

This example uses the ST_GeometryFromText function to construct two geometries and the ST_Crosses function to determine if they share interior points.

  • Query statement

    * |
    SELECT
      ST_Crosses(
        ST_GeometryFromText(
          'multipolygon (((10 10, 10 20, 20 20, 20 15 , 10 10), (50 40, 50 50, 60 50, 60 40, 50 40)))'
        ),
        ST_GeometryFromText(
          'multipolygon (((10 10, 10 20, 20 20, 20 15 , 10 10), (50 40, 50 50, 60 50, 60 40, 50 50)))'
        )
      )
  • The query returns false.

ST_Disjoint

The ST_Disjoint function checks if two geometries are disjoint. It returns true if the geometries do not intersect.

Syntax

ST_Disjoint(x, y)

Parameters

Parameter

Description

x

A geometry value.

y

A geometry value.

Return value type

boolean

Examples

This example constructs two geometries with ST_GeometryFromText and then uses ST_Disjoint to check whether they intersect.

  • Query statement

    * |
    SELECT
       ST_Disjoint(
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 40)))'
        ),
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 50)))'
        )
      )
  • The query returns false.

ST_Equals function

The ST_Equals function determines whether two geometries are identical, returning true if they are.

Syntax

ST_Equals(x, y)

Parameters

Parameter

Description

x

The first geometry.

y

The second geometry.

Return value type

boolean

Examples

This example uses the ST_GeometryFromText function to construct two geometries and the ST_Equals function to check if they are identical.

  • Query statement

    * |
    SELECT
       ST_Equals(
        ST_GeometryFromText(
          'multipolygon(((10 10,10 20,20 20,20 15,10 10),(50 40,50 50,60 50,60 40,50 40)))'
        ),
        ST_GeometryFromText(
          'multipolygon(((10 10,10 20,20 20,20 15,10 10),(50 40,50 50,60 50,60 40,50 50)))'
        )
      )
  • The query returns false.

ST_Intersects function

Returns true if the planar projections of two geometries intersect.

Syntax

ST_Intersects(x, y)

Parameters

Parameter

Description

x

A value of type geometry.

y

A value of type geometry.

Return value type

boolean

Examples

Use the ST_GeometryFromText function to construct two geometries, and then use the ST_Intersects function to check if they intersect.

  • Sample query

    * |
    SELECT
       ST_Intersects(
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 40)))'
        ),
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 50)))'
        )
      )
  • The query and analysis result is true.

ST_Overlaps function

The ST_Overlaps function returns true if two geometries of the same dimension overlap, but neither completely contains the other.

Syntax

ST_Overlaps(x, y)

Parameters

Parameter

Description

x

The first input geometry.

y

The second input geometry.

Return value type

boolean

Examples

This example constructs two geometries using the ST_GeometryFromText function and then checks if they overlap using the ST_Overlaps function.

  • Query and analysis statement

    * |
    SELECT
      ST_Overlaps(
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 40)))'
        ),
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 50)))'
        )
      )
  • The query returns false.

ST_Relate function

The ST_Relate function determines if two geometries are related by checking if their interiors or boundaries intersect. It returns true if they are.

Syntax

ST_Relate(x, y, patternMatrix string)

Parameters

Parameter

Description

x

A geometry value.

y

A geometry value.

patternMatrix string

A DE-9IM pattern matrix string. The value is of type varchar.

Return value type

boolean

Examples

This example constructs two geometries with the ST_GeometryFromText function and then uses the ST_Relate function to check if they are spatially related.

  • Query statement

    * |
    SELECT
      ST_Relate(
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 40)))'
        ),
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 50)))'
        ),  '****T****'
      )
  • The query returns true.

ST_Touches function

The ST_Touches function returns true if two geometries touch at their boundaries but their interiors do not intersect.

Syntax

ST_Touches(x, y)

Parameters

Parameter

Description

x

The first geometry.

y

The second geometry.

Return value type

Returns a boolean value.

Examples

The following query uses the ST_GeometryFromText function to create two geometries and the ST_Touches function to check if they touch.

  • Query statement

    * |
    SELECT
       ST_Touches(
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 40)))'
        ),
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 50)))'
        )
      )
  • The query returns false.

ST_Within function

The ST_Within function returns true if the first geometry is completely within the second geometry and their boundaries do not intersect.

Syntax

ST_Within(x, y)

Parameters

Parameter

Description

x

The first input geometry.

y

The second input geometry.

Return value type

boolean

Examples

This example constructs two geometries using the ST_GeometryFromText function and then uses the ST_Within function to determine if the first geometry is completely within the second.

  • Query and analysis statement

    * |
    SELECT
      ST_Within(
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 40)))'
        ),
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 50)))'
        )
      )
  • The query returns false.

ST_Area function

The ST_Area function calculates the projected area of a geometry on a two-dimensional plane by using Euclidean distance.

Syntax

ST_Area(x)

Parameters

Parameter

Description

x

The input geometry.

Return value type

double

Examples

This example calculates the area of a multipolygon.

  • Query statement

    * |
    SELECT
      ST_Area(
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 40)))'
        )
      )
  • Returns -25.0.

ST_Centroid function

The ST_Centroid function returns the mathematical centroid of an input geometry as a point.

Syntax

ST_Centroid(x)

Parameters

Parameter

Description

x

The input geometry.

Return value type

geometry

Examples

This example calculates the centroid of a multipolygon geometry.

  • Query and analysis statement

    * |
    SELECT
      ST_Centroid(
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 40)))'
        )
      )
  • The statement returns POINT (176.66666666666669 131.66666666666669).

ST_CoordDim function

The ST_CoordDim function returns the coordinate dimension of a geometry.

Syntax

ST_CoordDim(x)

Parameters

Parameter

Description

x

A geometry value.

Return value type

bigint

Examples

Use the ST_GeometryFromText function to construct a geometry and then use the ST_CoordDim function to return its coordinate dimension.

  • Query statement

    * |
    SELECT
      ST_CoordDim(
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 40)))'
        )
      )
  • The query returns 2.

ST_Dimension function

Returns the inherent dimension of a geometry, which cannot exceed the coordinate dimension.

Syntax

ST_Dimension(x)

Parameters

Parameter

Description

x

A geometry value.

  • If x is a point or an empty geometry, the function returns 0.

  • If x is a line string, the function returns 1.

  • If x is a polygon, the function returns 2.

  • If x is a geometry collection, the function returns the maximum dimension of the geometries in the collection.

Return value type

bigint

Examples

This example uses ST_Dimension to find the inherent dimension of a geometry created by ST_GeometryFromText.

  • Query statement

    * |
    SELECT
      ST_Dimension(
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 40)))'
        )
      )
  • The query returns 2.

ST_Distance function

Returns the minimum distance between two geometries.

Syntax

ST_Distance(x, y)

Parameters

Parameter

Description

x

A geometry value.

y

A geometry value.

Return value type

double

Examples

This example uses the ST_GeometryFromText function to create two geometries and the ST_Distance function to calculate the minimum distance between them.

  • Query statement

    * |
    SELECT
      ST_Distance(
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 50)))'
        ),
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 40)))'
        )
      )
  • The query result is 0.0.

ST_EndPoint function

ST_EndPoint returns the last point of a line string.

Syntax

ST_EndPoint(x)

Parameters

Parameter

Description

x

A value of the geometry type.

Return value type

A value of the point type.

Examples

Construct a line string with ST_LineFromText, and then use ST_EndPoint to return the last point.

  • Query and analysis statement

    * |
    SELECT
      ST_EndPoint(
        ST_LineFromText(
          'linestring (10 10,20 20)'
        )
      )
  • Returns POINT (20 20).

ST_IsClosed

The ST_IsClosed function returns true if a geometry is closed.

Syntax

ST_IsClosed(x)

Parameters

Parameter

Description

x

The geometry to check.

Return value type

A boolean value.

Examples

This example uses ST_LineFromText to construct a line string and ST_IsClosed to check if the line string is closed.

  • Query statement

    * |
    SELECT
      ST_IsClosed(
        ST_LineFromText(
          'linestring (10.05 10.28 , 20.95 20.89 )'
        )
      )
  • Query result: false

ST_IsEmpty function

The ST_IsEmpty function returns true if the input geometry is empty.

Syntax

ST_IsEmpty(x)

Parameters

Parameter

Description

x

The input must be a value of the geometry type.

Return value type

A boolean value.

Examples

Use the ST_Point function to create a point, and then the ST_IsEmpty function to check if it is empty.

  • Query statement

    * | SELECT ST_IsEmpty(ST_Point(1,1))
  • The query and analysis results are false.

ST_IsRing function

The ST_IsRing function returns true if the input geometry is a ring (a closed and simple line string).

Syntax

ST_IsRing(x)

Parameters

Parameter

Description

x

The parameter must be of type geometry.

Return value type

Boolean

Examples

This example constructs a line string with ST_LineFromText and then checks if it is a ring with ST_IsRing.

  • Query statement

    * |
    SELECT
      ST_IsRing(
        ST_LineFromText(
          'linestring (10.05 10.28,20.95 20.89 )'
        )
      )
  • The query returns false.

ST_Length function

The ST_Length function calculates the 2D projected length of a line string using Euclidean distance. For a multilinestring, it returns the sum of the lengths of the component line strings.

Syntax

ST_Length(x)

Parameters

Parameter

Description

x

A geometry value.

Return value type

A double value.

Examples

Use ST_LineFromText to construct a line string and ST_Length to calculate its length.

  • Query statement

    * |
    SELECT
      ST_Length(
        ST_LineFromText(
          'linestring (10.05 10.28,20.95 20.89)'
        )
      )
  • The query returns 15.211249126879752.

ST_NumPoints function

Returns the number of points in a geometry.

Syntax

ST_NumPoints(x)

Parameters

Parameter

Description

x

A geometry value.

Return value type

bigint

Examples

This example first constructs a line string with the ST_LineFromText function, and then uses the ST_NumPoints function to return the number of points in it.

  • Query statement

    * |
    SELECT
      ST_NumPoints(
        ST_LineFromText('linestring (10 10,20 20)')
      )
  • Query result: 2

ST_NumInteriorRing function

Returns the number of interior rings in a geometry.

Syntax

ST_NumInteriorRing(x)

Parameters

Parameter

Description

x

A geometry object.

Return value type

A bigint value.

Examples

This example uses ST_GeometryFromText to construct a geometry and ST_NumInteriorRing to calculate the number of its interior rings.

  • Query statement

    * |
    SELECT
      ST_NumInteriorRing(
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 40)))'
        )
      )
  • The query returns 1.

ST_StartPoint function

Returns the first point of a line string.

Syntax

ST_StartPoint(x)

Parameters

Parameter

Description

x

Specifies the input line string.

Return value type

point

Examples

This example creates a line string with the ST_LineFromText function and then returns the first point by using the ST_StartPoint function.

  • Query statement

    * |
    SELECT
      ST_StartPoint(
        ST_LineFromText(
          'linestring (10 10,20 20 )'
        )
      )
  • Query and analysis results: POINT (10 10).

ST_X function

Returns the X-coordinate of an input point.

Syntax

ST_X(x)

Parameters

Parameter

Description

x

The parameter must be a point.

Return value type

The return type is double.

Examples

This example uses the ST_Point function to construct a point and ST_X to return its X-coordinate.

  • Query statement

    * | SELECT ST_X(ST_Point(1,3))
  • The query returns 1.0.

ST_XMax function

ST_XMax returns the maximum x-coordinate of a geometry.

Syntax

ST_XMax(x)

Parameters

Parameter

Description

x

A geometry value.

Return value type

Returns a double.

Examples

Use the ST_GeometryFromText function to construct a geometry, and then use the ST_XMax function to return its maximum x-coordinate.

  • Query statement

    * |
    SELECT
      ST_XMax(
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 40)))'
        )
      )
  • The query returns 60.0.

ST_XMin function

The ST_XMin function returns the minimum x-coordinate of a geometry.

Syntax

ST_XMin(x)

Parameters

Parameter

Description

x

The input geometry.

Return value type

double

Examples

This example constructs a geometry with the ST_GeometryFromText function and then uses the ST_XMin function to return its minimum x-coordinate.

  • Query statement

    * |
    SELECT
      ST_XMin(
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 40)))'
        )
      )
  • Query results: 10.0

ST_Y function

Returns the y-coordinate of an input point.

Syntax

ST_Y(x)

Parameters

Parameter

Description

x

A value of the point type.

Return value type

A value of the double type.

Examples

This example uses the ST_Point function to create a point and the ST_Y function to retrieve its y-coordinate.

  • Query and analysis statement

    * | SELECT ST_Y(ST_Point(1,3))
  • Query and analysis results: 3.0

ST_YMax function

The ST_YMax function returns the maximum y-coordinate of a geometry.

Syntax

ST_YMax(x)

Parameters

Parameter

Description

x

A geometry value.

Return value type

double

Examples

This example constructs a geometry with the ST_GeometryFromText function and returns its maximum y-coordinate with the ST_YMax function.

  • Query and analysis statement

    * |
    SELECT
      ST_YMax(
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 40)))'
        )
      )
  • The query and analysis result is 50.0.

ST_YMin function

Returns the minimum Y-coordinate of a geometry.

Syntax

ST_YMin(x)

Parameters

Parameter

Description

x

The input geometry.

Return value type

double

Examples

This example uses the ST_GeometryFromText function to construct a geometry and the ST_YMin function to return its minimum Y-coordinate.

  • Query and analysis statement

    * |
    SELECT
      ST_YMin(
        ST_GeometryFromText(
          'multipolygon (((10 10,10 20,20 20,20 15,10 10), (50 40,50 50,60 50,60 40,50 40)))'
        )
      )
  • The result is 10.0.

bing_tile

The bing_tile function creates a Bing tile.

Syntax

  • Creates a Bing tile from an x-coordinate, a y-coordinate, and a zoom level.

    bing_tile(x, y, zoom_level)
  • Creates a Bing tile from a quadtree key.

    bing_tile(quadKey)

Parameters

Parameter

Description

x

The x-coordinate. Must be an integer.

y

The y-coordinate. Must be an integer.

zoom_level

The zoom level. Must be an integer from 1 to 23.

quadKey

The quadtree key.

Return value type

Returns a Bing tile.

Examples

  • Example 1: Create a Bing tile from an x-coordinate, a y-coordinate, and a zoom level.

    • Query statement

      * | SELECT bing_tile(10, 20, 20)
    • Query and analysis results: {"x":10,"y":20,"zoom":20}

  • Example 2: Create a Bing tile from a quadtree key.

    • Query statement

      * | SELECT bing_tile(bing_tile_quadkey(bing_tile(10, 20, 20)))
    • Query and analysis results: {"x":10,"y":20,"zoom":20}

Bing_tile_at function

The bing_tile_at function creates a Bing tile from a latitude, longitude, and zoom level.

Syntax

bing_tile_at(x, y, zoom_level)

Parameters

Parameter

Description

x

The latitude, as a double value in the range [-85.05112878, 85.05112878].

y

The longitude, as a double value in the range [-180, 180].

zoom_level

The zoom level, as an integer from 1 to 23.

Return value type

A BingTile object.

Examples

This example creates a Bing tile.

  • Query

    * | SELECT bing_tile_at(47.265511, -122.465691, 12)
  • The query returns {"x":654,"y":1436,"zoom":12}.

bing_tile_coordinates function

Returns the X- and Y-coordinates of a specified Bing tile.

Syntax

bing_tile_coordinates(x)

Parameters

Parameter

Description

x

A BingTile value.

Return value type

Returns an array of two integers: [X, Y].

Examples

This example retrieves the coordinates for a specified Bing tile.

  • Query statement

    * | SELECT bing_tile_coordinates(bing_tile_at(47.265511, -122.465691, 12))
  • Result: [654,1436].

bing_tile_polygon

Returns the polygon representation of a Bing tile.

Syntax

bing_tile_polygon(x)

Parameters

Parameter

Description

x

A BingTile value.

Return value type

polygon

Examples

Returns the polygon representation of a Bing tile.

  • Query statement

    * | SELECT bing_tile_polygon(bing_tile_at(30.26, 120.19, 12))
  • Query result: POLYGON ((120.146484375 30.297017883372042, 120.146484375 30.221101852485987, 120.234375 30.221101852485987, 120.234375 30.297017883372042, 120.146484375 30.297017883372042))

Bing_tile_quadkey

The bing_tile_quadkey function returns the quadtree key for a Bing tile.

Syntax

bing_tile_quadkey(x)

Parameters

Parameter

Description

x

A BingTile value.

Return value type

varchar

Examples

This example converts a tile at coordinates (10, 20) and zoom level 20 into its corresponding quadtree key.

  • Query statement

    * | SELECT bing_tile_quadkey(bing_tile(10, 20, 20))
  • The query returns the quadtree key 000000000000021210.

bing_tile_zoom_level function

Returns the zoom level of a Bing tile.

Syntax

bing_tile_zoom_level(x)

Parameters

Parameter

Description

x

A BingTile object.

Return value type

double

Examples

The following example calculates the zoom level for a specific Bing tile.

  • Query statement

    * | SELECT bing_tile_zoom_level(bing_tile(10, 20, 20))
  • Query result: 20.