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
| Parameter | Description |
|---|---|
geom | The 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)该文章对您有帮助吗?