Returns the number of interior rings (holes) of a polygon geometry.
Syntax
integer ST_NumInteriorRings(geometry aPolygon)Parameters
| Parameter | Description |
|---|---|
aPolygon | The polygon geometry to query. |
Usage notes
Returns NULL if the input geometry is not a polygon.
Examples
Query interior ring count from a table
SELECT gid, ST_NumInteriorRings(geom) AS num_holes
FROM sometable;Compare ST_NumInteriorRings and ST_NRings
ST_NRings counts all rings (exterior + interior), while ST_NumInteriorRings counts only interior rings (holes):
SELECT ST_NRings(geom), ST_NumInteriorRings(geom)
FROM (
SELECT 'POLYGON((1 0,0 3,3 0,1 0),(1 0,2 0,0 2,1 0))'::geometry AS geom
) AS t;Output:
st_nrings | st_numinteriorrings
-----------+---------------------
2 | 1
(1 row)The polygon has 2 rings total (1 exterior + 1 interior), so ST_NRings returns 2 and ST_NumInteriorRings returns 1.
See also
ST_NRings — returns the total number of rings (exterior + interior) for a polygon or MultiPolygon