ST_Polygonize is an aggregate function that builds polygons from a set of input lines. It returns a GeometryCollection containing all polygons formed by the constituent lines of the input geometries.
Syntax
geometry ST_Polygonize(geometry set geomField);
geometry ST_Polygonize(geometry[] geomArray);Parameters
| Parameter | Description |
|---|---|
| geomField | The geometry fields in the dataset. |
| geomArray | An array of geometry objects. |
Usage notes
Input lines must be correctly noded. All intersection points must be inserted as vertices before polygonizing.
`GeometryCollection` output. Most third-party tools do not support
GeometryCollectionobjects. Use ST_Dump to expand the result into individual polygon rows.
Examples
Build polygons from an array of lines
The following example builds a polygon from four line segments that form a closed square.
SELECT ST_AsText(
ST_Polygonize(
ARRAY[
'LINESTRING(0 0,0 1)'::geometry,
'LINESTRING(0 1,1 1)'::geometry,
'LINESTRING(1 1,1 0)'::geometry,
'LINESTRING(0 0,1 0)'::geometry
]
)
);Output:
st_astext
----------------------------------------------------
GEOMETRYCOLLECTION(POLYGON((0 0,0 1,1 1,1 0,0 0)))
(1 row)What's next
ST_Dump: Expand a
GeometryCollectioninto individual geometry rows.
该文章对您有帮助吗?