Geometry Accessors

st_boundary

Geometry st_boundary(Geometry geom)

This function returns the boundary, or an empty geometry of appropriate dimension, if geom is empty.

Example:

  • Query command:

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

  • The query result is as follows:
    LINESTRING (30 10, 40 40, 20 40, 10 20, 30 10)

st_coordDim

Int st_coordDim(Geometry geom)

This function returns the number of dimensions of the coordinates of Geometry geom.

Example:

  • Query command:

    select st_coordDim(st_boundary(st_geomFromWKT(location))) from geotbl where id='2'

  • The query result is as follows:
    2

st_dimension

Int st_dimension(Geometry geom)

This function returns the inherent number of dimensions of this Geometry object, which must be less than or equal to the coordinate dimension.

Example:

  • Query command:

    select st_dimension(st_boundary(st_geomFromWKT(location))) from geotbl where id='2'

  • The query result is as follows:
    1

st_envelope

Geometry st_envelope(Geometry geom)

This function returns a Geometry representing the bounding box of geom.

Example:

  • Query command:

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

  • The query result is as follows:
    POLYGON ((10 10, 10 40, 40 40, 40 10, 10 10))

st_exteriorRing

LineString st_exteriorRing(Geometry geom)

This function returns a LineString representing the exterior ring of the geometry; returns null if the Geometry is not a Polygon.

Example:

  • Query command:

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

  • The query result is as follows:
    LINESTRING (30 10, 40 40, 20 40, 10 20, 30 10)

st_geometryN

Geometry st_geometryN(Geometry geom, Geometry n)

This function returns the nth Geometry (1-based index) of geom if the Geometry is a GeometryCollection, or geom if it is not.

Example:

  • Query command:

    select st_astext(st_geometryN(st_geomFromWKT(location),1)) from geotbl where id='1'

  • The query result is as follows:
    POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))

st_interiorRingN

Geometry st_interiorRingN(Geometry geom, Int n)

This function returns the nth interior LineString ring of the Polygon geom. If the geometry is not a Polygon or the given n is out of range, this function returns null.

Example:

  • Query command:

    select st_astext(st_interiorRingN(st_geomFromWKT(location),1)) from geotbl where id='4'

  • The query result is as follows:
    LINESTRING (20 30, 35 35, 30 20, 20 30)

st_isClosed

Boolean st_isClosed(Geometry geom)

This function returns true if geom is a LineString or MultiLineString and its start and end points are coincident. This function returns true for all other Geometry types.

Example:

  • Query command:

    select st_isClosed(st_geomFromWKT(location)) from geotbl where id='6'

  • The query result is as follows:
    TRUE

st_isCollection

Boolean st_isCollection(Geometry geom)

This function returns true if geom is a GeometryCollection.

Example:

  • Query command:

    select st_isCollection(st_geomFromWKT(location)) from geotbl where id='7'

  • The query result is as follows:
    TRUE

st_isEmpty

Boolean st_isEmpty(Geometry geom)

This function returns true if geom is empty.

Example:

  • Query command:

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

  • The query result is as follows:
    TRUE

st_isRing

Boolean st_isRing(Geometry geom)

This function returns true if geom is a LineString or a MultiLineString and is both closed and simple.

Example:

  • Query command:

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

  • The query result is as follows:
    TRUE

st_isSimple

Boolean st_isSimple(Geometry geom)

This function returns true if geom has no anomalous geometric points, such as self intersection or self tangency.

Example:

  • Query command:

    select st_isSimple(st_geomFromWKT(location)) from geotbl where id='2'

  • The query result is as follows:
    TRUE

st_isValid

Boolean st_isValid(Geometry geom)

This function returns true if the Geometry is topologically valid according to the OGC SFS specification.

Example:

  • Query command:

    select st_isValid(st_geomFromWKT(location)) from geotbl where id='3'

  • The query result is as follows:
    TRUE

st_numGeometries

Int st_numGeometries(Geometry geom)

If geom is a GeometryCollection, this function returns the number of geometries. Otherwise, it returns 1.

Example:

  • Query command:

    select st_numGeometries(st_geomFromWKT(location)) from geotbl where id='3'

  • The query result is as follows:
    2

st_numPoints

Int st_numPoints(Geometry geom)

This function returns the number of vertices in Geometry geom.

Example:

  • Query command:

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

  • The query result is as follows:
    9

st_pointN

Point st_pointN(Geometry geom, Int n)

If geom is a LineString, this function returns the nth vertex of geom as a point. Negative values are counted backwards from the end of the LineString. This function returns null if geom is not a LineString.

Example:

  • Query command:

    select st_astext(st_pointN(st_geomFromWKT(location),2)) from geotbl where id='5'

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

st_x

Float st_x(Geometry geom)

If geom is a point, this function returns the X coordinate of that point.

Example:

  • Query command:

    select st_x(st_geomFromWKT(location)) from geotbl where id='6'

  • The query result is as follows:
    11

st_y

Float st_y(Geometry geom)

If geom is a point, this function returns the Y coordinate of that point.

Example:

  • Query command:

    select st_y(st_geomFromWKT(location)) from geotbl where id='6'

  • The query result is as follows:
    22