ST_GeometryType

更新时间:
复制 MD 格式

Returns the geometry type of a geometry object as a string prefixed with ST_.

Syntax

text ST_GeometryType(geometry g1);

Parameters

ParameterDescription
g1The geometry object to inspect.

Return values

Returns a string indicating the geometry type of the input. Possible values include:

  • ST_Point

  • ST_LineString

  • ST_Polygon

  • ST_MultiPoint

  • ST_MultiLineString

  • ST_MultiPolygon

  • ST_GeometryCollection

  • ST_PolyhedralSurface

Usage notes

  • M coordinates ignored: ST_GeometryType does not reflect whether the geometry contains M coordinates. For example, both POINT(1 0) and POINTM(1 0 1) return ST_Point. To check for M coordinates, use GeometryType instead.

  • Z coordinates preserved: The function supports 3D geometries and does not drop Z coordinates.

  • Polyhedral surfaces supported: The function handles polyhedral surface geometries.

Examples

Point geometry:

SELECT ST_GeometryType('POINT(1 0)'::geometry);
 st_geometrytype
-----------------
 ST_Point
(1 row)

Point with M coordinates:

SELECT ST_GeometryType('POINTM(1 0 1)'::geometry);
 st_geometrytype
-----------------
 ST_Point
(1 row)

M coordinates do not affect the returned type string.

LineString geometry:

SELECT ST_GeometryType('LINESTRING(0 0, 1 1, 2 2)'::geometry);
 st_geometrytype
-----------------
 ST_LineString
(1 row)

Polyhedral surface:

SELECT ST_GeometryType(
  ST_GeomFromEWKT('POLYHEDRALSURFACE(((0 0 0,0 0 1,0 1 1,0 1 0,0 0 0)),
    ((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)))')
);
 st_geometrytype
--------------------
 ST_PolyhedralSurface
(1 row)

See also

  • GeometryType — Returns the geometry type as an uppercase OGC string and indicates whether M coordinates are present.