ST_DumpRings

更新时间:
复制 MD 格式

Extracts the outer ring and inner rings of a polygon as a set of geometry_dump rows.

Syntax

geometry_dump[]  ST_DumpRings(geometry aPolygon);

Parameters

ParameterDescription
aPolygonThe polygon object to extract rings from.

Description

ST_DumpRings returns a set of geometry_dump rows, one per ring. Each row contains two fields:

  • path: An integer array indicating the ring index. {0} identifies the outer ring. A value greater than 0 indicates an inner ring.

  • geom: The ring represented as a polygon object.

Limitations:

  • Accepts only polygon objects. MultiPolygon objects are not supported.

  • Supports 3D objects.

Examples

The following example extracts the outer ring and one inner ring from a polygon with a hole:

SELECT (t.dump).path, ST_AsText((t.dump).geom)
FROM (
  SELECT ST_DumpRings('POLYGON((0 0,0 4,4 4,4 0,0 0),(1 1,2 1,2 2,1 2,1 1))'::geometry) AS dump
) AS T;

Output:

 path |           st_astext
------+--------------------------------
 {0}  | POLYGON((0 0,0 4,4 4,4 0,0 0))
 {1}  | POLYGON((1 1,2 1,2 2,1 2,1 1))
(2 rows)

{0} is the outer ring (the boundary of the square). {1} is the inner ring (the hole).