Returns the number of rings in a polygonal geometry.
Syntax
integer ST_NRings(geometry geomA)Parameters
| Parameter | Description |
|---|---|
geomA | The input geometry. Accepts Polygon and MultiPolygon types. |
Usage notes
Unlike ST_NumInteriorRings,
ST_NRingscounts both the exterior ring and all interior rings. For a simple polygon with no holes,ST_NRingsreturns1andST_NumInteriorRingsreturns0.Supports 3D geometries. Z coordinates are preserved.
Supports circular strings and curves.
Examples
The following query runs both functions on the same geometry, showing the difference between total ring count and interior ring count:
SELECT
ST_NRings(geom) AS nrings,
ST_NumInteriorRings(geom) AS ninterior_rings
FROM (
SELECT 'POLYGON((1 0,0 3,3 0,1 0),(1 0,2 0,0 2,1 0))'::geometry AS geom
) AS t; nrings | ninterior_rings
--------+-----------------
2 | 1
(1 row)The polygon has one exterior ring and one interior ring (hole), so ST_NRings returns 2 while ST_NumInteriorRings returns 1.
For a polygon with no interior rings:
SELECT ST_NRings('POLYGON((1 0,0 3,3 0,1 0))'::geometry); st_nrings
-----------
1
(1 row)See also
该文章对您有帮助吗?