ST_NumGeometries

更新时间:
复制 MD 格式

Returns the number of geometries in a collection. For a GeometryCollection or any MULTI type, the function returns the count of component geometries. For a single geometry, it returns 1. For all other inputs, it returns NULL.

Syntax

integer ST_NumGeometries(geometry geom);

Parameters

ParameterDescription
geomThe geometry object to evaluate.

Usage notes

This function supports polyhedral surfaces, triangles, triangulated irregular network (TIN) surfaces, and 3D objects.

Examples

Count the geometries in a MULTIPOLYGON:

SELECT ST_NumGeometries('MULTIPOLYGON(((1 0,0 3,3 0,1 0)),((1 0,2 0,0 2,1 0)))'::geometry);

Output:

 st_numgeometries
------------------
                2
(1 row)

Count the geometries in a GeometryCollection:

SELECT ST_NumGeometries('GeometryCollection(POINT(1 0),POLYGON((1 0,2 0, 0 2,1 0)))'::geometry);

Output:

 st_numgeometries
------------------
                2
(1 row)