An aggregate function that builds possible polygons from a set of linework geometries and returns them as a GeometryCollection.
Syntax
geometry ST_Polygonize(geometry set geomField);
geometry ST_Polygonize(geometry[] geomArray);Parameters
| Parameter | Description |
|---|---|
geomField | The geometry column in the input dataset. Used when calling the function as an aggregate over a result set. |
geomArray | An array of geometry objects from which polygons are formed. |
Usage notes
The constituent lines of each input geometry must be correctly noded before calling this function. Unnoded input produces incomplete or incorrect polygon output.
Most third-party tools do not support GeometryCollection results. Use ST_Dump to expand the collection into individual polygon rows.
Examples
The following example passes four LINESTRING geometries that form a closed square. ST_Polygonize assembles them into a single polygon and returns it inside a GeometryCollection.
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
]
)
);Result:
st_astext
----------------------------------------------------
GEOMETRYCOLLECTION(POLYGON((0 0,0 1,1 1,1 0,0 0)))
(1 row)该文章对您有帮助吗?