ST_DumpRings — Returns a set of geometry_dump rows for the exterior and interior rings of a Polygon.
geometry_dump[] ST_DumpRings(geometry a_polygon);
A set-returning function (SRF) that extracts the rings of a polygon. It returns a set of geometry_dump rows, each containing a geometry (geom field) and an array of integers (path field).
The geom field contains each ring as a POLYGON. The path field is an integer array of length 1 containing the polygon ring index. The exterior ring (shell) has index 0. The interior rings (holes) have indices of 1 and higher.
|
|
|
This only works for POLYGON geometries, not MULTIPOLYGONs. Use ST_Dump to extract polygon elements from polygonal geometries: |
Availability: PostGIS 1.1.3. Requires PostgreSQL 7.3 or higher.
This function supports 3d and will not drop the z-index.
Extracting all rings as polygons.
SELECT polyTable.field1, polyTable.field1,
(ST_DumpRings(polyTable.geom)).geom As geom
FROM polyTable
Extracting shell and holes from a polygon.
SELECT path, ST_AsText(geom) As geom
FROM ST_DumpRings(
'POLYGON ((1 9, 9 9, 9 1, 1 1, 1 9), (2 2, 2 3, 3 3, 3 2, 2 2), (4 2, 4 4, 6 4, 6 2, 4 2))');
path | geom
------+--------------------------------
{0} | POLYGON((1 9,9 9,9 1,1 1,1 9))
{1} | POLYGON((2 2,2 3,3 3,3 2,2 2))
{2} | POLYGON((4 2,4 4,6 4,6 2,4 2))
geometry_dump, ST_GeomFromEWKT, ST_Dump, ST_GeometryN, ST_NumGeometries