Name

ST_NumGeometries — 返回几何图形集合中的元素数。

Synopsis

integer ST_NumGeometries(geometry geom);

描述

返回几何图形的数量。如果GEOMETRYCOLLECTION(或MULTI*)为GEOMETRYCOLLECTION,则返回几何图形的数量,对于单个几何图形将返回1,否则返回NULL。

增强:2.0.0引入了对多面体曲面、三角形和三角网的支持。

已更改:2.0.0在早期版本中,如果几何体不是集合/多类型,则返回NULL。2.0.0+现在为单个几何图形返回1,例如多边形、线条、点。

This method implements the SQL/MM specification. SQL-MM 3:9.1.4

This function supports 3d and will not drop the z-index.

This function supports Polyhedral surfaces.

This function supports Triangles and Triangulated Irregular Network Surfaces (TIN).

示例

--Prior versions would have returned NULL for this -- in 2.0.0 this returns 1
SELECT ST_NumGeometries(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'));
--result
1

--Geometry Collection Example - multis count as one geom in a collection
SELECT ST_NumGeometries(ST_GeomFromEWKT('GEOMETRYCOLLECTION(MULTIPOINT((-2 3),(-2 2)),
LINESTRING(5 5 ,10 10),
POLYGON((-7 4.2,-7.1 5,-7.1 4.3,-7 4.2)))'));
--result
3

另请参阅

ST_GeometryN, ST_Multi