This topic describes the ST_Polygonize function. This function is an aggregate function. This function returns a GeometryCollection object that contains possible polygon objects formed by the constituent lines of input geometry objects.

Syntax

geometry  ST_Polygonize(geometry set  geomField);
geometry  ST_Polygonize(geometry[]  geomArray);

Parameters

Parameter Description
geomfield The fields of the geometry objects that you want to specify in the dataset.
geomArray The array of geometry objects that you want to specify.

Description

  • In most cases, third-party tools do not support GeometryCollection objects. You can use this function with the ST_Dump function to expand a collection of polygon objects into separate polygon objects.
  • Before you use this function, the constituent lines of input geometry objects must be correctly noded.

Examples

Results returned by using the default parameter settings:
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]));
                     st_astext
----------------------------------------------------
 GEOMETRYCOLLECTION(POLYGON((0 0,0 1,1 1,1 0,0 0)))
(1 row)