Name

ST_NumGeometries — Returns the number of geometries in a GeometryCollection.

Synopsis

integer ST_NumGeometries(bytea Geometry);

Alias

NumGeometries

Description

Returns the number of geometries in a GeometryCollection.

[Note]

If the input Geometry is not a GeometryCollection, Jaspa also counts them, instead of returning Null as specified in SQL-MM.

Coordinate Dimensions
2D3DM
Spatial Standards Support
OGC SFS for SQL. 1.1 (1999)OGC SFS for SQL. 1.1.0 (2005)OGC SFS for SQL. 1.2.0 (2006))SQL-MM Part 3
2.1.2.17.2.16.17.2.159.1.4

Examples

SELECT ST_NumGeometries(ST_GeomFromText('GEOMETRYCOLLECTION(
POINT (5 5),LINESTRING (0 0, 0 50),
POLYGON ((20 20, 50 20, 50 50, 20 50, 20 20)))'));
--Result
3

--Not a GeometyCollection--
SELECT ST_NumGeometries(ST_GeomFromText('LINESTRING (0 0, 10 10, 20 10, 10 10)'));
--Result
1

Related functions

ST_GeometryN