名称

ST_DumpRings — 返回多边形外环和内环的一组geometry_dump行。

大纲

geometry_dump[] ST_DumpRings(geometry a_polygon);

描述

提取多边形环的集合返回函数 (SRF)。它返回一组geometry_dump 行,每行包含一个几何图形(geom字段)和一个整数数组(path 字段)。

geom 字段将每个环包含为 POLYGON。path字段是一个长度为 1 的整数数组,包含多边形环索引。外环(壳)的索引为 0。内环(孔)的索引为 1 及更高。

[注意]

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

可用性:需要 PostGIS 1.1.3 PostgreSQL 7.3 或更高版本。

该函数支持 3d 并且不会丢失 z-index。

示例

将所有环提取为 polygon。

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

从 polygon 中提取外壳(shell)和洞(holes)。

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))');
栅格输出
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);
栅格输出
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