ST_InteriorRingN
What is ST_InteriorRingN?
ST_InteriorRingN is a PostGIS function that returns the Nth interior ring (hole) of a POLYGON as a closed LINESTRING. Indexing is 1-based.
ST_InteriorRingN(geometry polygon, integer n) → geometryOnly POLYGON input is supported. Out-of-range indices return NULL; MULTIPOLYGON input also returns NULL.
When would you use ST_InteriorRingN?
Use ST_InteriorRingN to pick a specific hole from a polygon — for example to extract known annotated holes, compute hole area separately from the shell, or extract a specific internal courtyard boundary:
1SELECT id,
2 ST_Length(ST_InteriorRingN(geom, 1)) AS first_hole_perimeter
3FROM parcels
4WHERE ST_NumInteriorRings(geom) >= 1;For iterating over every hole, prefer ST_DumpRings, which returns every ring in one set-returning call.
FAQs
Is ST_InteriorRingN 0- or 1-based?
1-based. ST_InteriorRingN(p, 1) returns the first hole. Use ST_NumInteriorRings(p) to bound the index.
What is returned if the polygon has no holes?
NULL. Always check ST_NumInteriorRings(p) >= n before calling, or filter with WHERE ST_NumInteriorRings(geom) > 0.
How is ST_InteriorRingN different from ST_DumpRings?
ST_InteriorRingN returns one specific hole as a LINESTRING. ST_DumpRings returns a set of rows, one per ring (including the exterior), each as a polygon. Use ST_InteriorRingN for targeted access, ST_DumpRings for iteration.
What about MultiPolygon input?
Returns NULL. Unpack the multi with ST_Dump or select a specific component with ST_GeometryN first.