Nom

ST_DumpRings — Renvoie un ensemble de lignes geometry_dump pour les anneaux extérieurs et intérieurs d'un polygone.

Synopsis

geometry_dump[] ST_DumpRings(geometry a_polygon);

Description

Une fonction de retour d'ensemble (SRF) qui extrait les anneaux d'un polygone. Elle renvoie un ensemble de geometry_dump lignes, chacune contenant une géométrie (champ geom) et un tableau d'entiers (champ path).

Le champ geom contient chaque anneau sous forme de POLYGONE. Le champ path est un tableau d'entiers de longueur 1 contenant l'indice de l'anneau du polygone. L'anneau extérieur (coquille) a l'indice 0. Les anneaux intérieurs (trous) ont des indices de 1 et plus.

[Note]

This only works for POLYGON geometries, not MULTIPOLYGONs. Use ST_Dump to extract polygon elements from polygonal geometries: ST_DumpRings((ST_Dump(geom)).geom )

Disponibilité : PostGIS 1.1.3. Nécessite PostgreSQL 7.3 ou plus.

Cette fonction prend en charge la 3D et ne supprime pas l'indice z.

Exemples

Extracting all rings as polygons.

Code
SELECT polyTable.field1, polyTable.field1,
      (ST_DumpRings(polyTable.geom)).geom As geom
FROM polyTable

Extracting shell and holes from a polygon.

Code
SELECT path,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))');
Export de raster
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))
Figure
Geometry figure for visual-st-dumprings-01

Finding interior rings which lie close to the exterior ring.

Code
WITH poly AS (
  SELECT 'POLYGON ((
      0 0, 10 0, 10 10, 0 10, 0 0
    ), (
      1 1, 1 2, 2 2, 2 1, 1 1
    ), (
      8.5 1, 8.5 2, 9.5 2, 9.5 1, 8.5 1
    ))'::geometry AS geom
),
rings AS (
  SELECT d.path[1] AS ring_no,
         ST_Boundary(d.geom) AS ring_geom
  FROM poly
  CROSS JOIN LATERAL ST_DumpRings(poly.geom) AS d
),
shell AS (
  SELECT ring_geom
  FROM rings
  WHERE ring_no = 0
),
holes AS (
  SELECT ring_no, ring_geom
  FROM rings
  WHERE ring_no > 0
)
SELECT h.ring_no,
       ST_Normalize(ST_Multi(ST_LineMerge(
         ST_Intersection(ST_Buffer(s.ring_geom, 1.0), h.ring_geom)
       ))) AS close_part
FROM shell AS s
JOIN holes AS h
  ON ST_DWithin(s.ring_geom, h.ring_geom, 1.0);
Export de raster
ring_no |                   close_part
---------+-------------------------------------------------
       1 | MULTILINESTRING((1 2,1 1,2 1))
       2 | MULTILINESTRING((8.5 1,9 1,9.5 1,9.5 2,9 2))
Figure
Geometry figure for visual-st-dumprings-02