You are on page 1of 2

PostGIS 1.5.

1 Manual
109 / 315

Examples
-

SELECT ST_NPoints(ST_GeomFromText(LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29


29.07)));
--result
4
--Polygon in 3D space
SELECT ST_NPoints(ST_GeomFromEWKT(LINESTRING(77.29 29.07 1,77.42 29.26 0,77.27 29.31
-1,77.29 29.07 3)))
--result
4

See Also
ST_NumPoints

7.4.20 ST_NRings
Name
ST_NRings If the geometry is a polygon or multi-polygon returns the number of rings.

Synopsis
integer ST_NRings(geometry geomA);

Description
If the geometry is a polygon or multi-polygon returns the number of rings. Unlike NumInteriorRings, it counts the outer rings as
well.
This function supports 3d and will not drop the z-index.
This method supports Circular Strings and Curves

Examples
SELECT ST_NRings(the_geom) As Nrings, ST_NumInteriorRings(the_geom) As ninterrings
FROM (SELECT ST_GeomFromText(POLYGON((1 2, 3 4, 5 6, 1 2))) As the_geom) As foo ;
nrings | ninterrings
--------+------------1 |
0
(1 row)

See Also
ST_NumInteriorRings

PostGIS 1.5.1 Manual


110 / 315

7.4.21 ST_NumGeometries
Name
ST_NumGeometries If geometry is a GEOMETRYCOLLECTION (or MULTI*) return the number of geometries, otherwise
return NULL.

Synopsis
integer ST_NumGeometries(geometry a_multi_or_geomcollection);

Description
Returns the number of Geometries. If geometry is a GEOMETRYCOLLECTION (or MULTI*) return the number of geometries,
otherwise return NULL.
This method implements the SQL/MM specification. SQL-MM 3: 9.1.4

Examples
--Although ST_NumGeometries will return null when passed a single, you can wrap in ST_Multi to force 1 or more for all geoms
SELECT ST_NumGeometries(ST_Multi(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

See Also
ST_GeometryN, ST_Multi

7.4.22 ST_NumInteriorRings
Name
ST_NumInteriorRings Return the number of interior rings of the first polygon in the geometry. This will work with both
POLYGON and MULTIPOLYGON types but only looks at the first polygon. Return NULL if there is no polygon in the geometry.

Synopsis
integer ST_NumInteriorRings(geometry a_polygon);

You might also like