名称

ST_Polygonize — 根据一组几何图形的线框计算形成的多边形集合。

语法

geometry ST_Polygonize(geometry set geomfield);

geometry ST_Polygonize(geometry[] geom_array);

说明

创建一个 GeometryCollection,其中包含由一组几何图形的线框形成的多边形。如果输入线框未形成任何多边形,则返回一个空的 GeometryCollection。

此函数创建覆盖所有定界区域的多边形。如果结果旨在形成一个有效的多边形几何图形,请使用 ST_BuildArea 来防止填充孔洞。

[Note]

输入线框必须正确地进行节点化,才能使此函数正常工作。为确保输入已进行节点化,请在多边形化之前对输入几何图形使用 ST_Node

[Note]

GeometryCollections 很难使用外部工具进行处理。使用 ST_Dump 将多边形化结果转换为单独的多边形。

由 GEOS 模块执行。

可用性:1.0.0RC1

示例

输入线

多边形化结果

WITH data(geom) AS (VALUES
   ('LINESTRING (180 40, 30 20, 20 90)'::geometry)
  ,('LINESTRING (180 40, 160 160)'::geometry)
  ,('LINESTRING (80 60, 120 130, 150 80)'::geometry)
  ,('LINESTRING (80 60, 150 80)'::geometry)
  ,('LINESTRING (20 90, 70 70, 80 130)'::geometry)
  ,('LINESTRING (80 130, 160 160)'::geometry)
  ,('LINESTRING (20 90, 20 160, 70 190)'::geometry)
  ,('LINESTRING (70 190, 80 130)'::geometry)
  ,('LINESTRING (70 190, 160 160)'::geometry)
)
SELECT ST_AsText( ST_Polygonize( geom ))
    FROM data;
    
------------------------------------------------------------------------------------------
GEOMETRYCOLLECTION (POLYGON ((180 40, 30 20, 20 90, 70 70, 80 130, 160 160, 180 40), (150 80, 120 130, 80 60, 150 80)), 
                    POLYGON ((20 90, 20 160, 70 190, 80 130, 70 70, 20 90)), 
                    POLYGON ((160 160, 80 130, 70 190, 160 160)), 
                    POLYGON ((80 60, 120 130, 150 80, 80 60)))

对线字符串表进行多边形化

SELECT ST_AsEWKT(ST_Polygonize(geom_4269)) As geomtextrep
FROM (SELECT geom_4269 FROM ma.suffolk_edges) As foo;

-------------------------------------
 SRID=4269;GEOMETRYCOLLECTION(POLYGON((-71.040878 42.285678,-71.040943 42.2856,-71.04096 42.285752,-71.040878 42.285678)),
 POLYGON((-71.17166 42.353675,-71.172026 42.354044,-71.17239 42.354358,-71.171794 42.354971,-71.170511 42.354855,
 -71.17112 42.354238,-71.17166 42.353675)))

--Use ST_Dump to dump out the polygonize geoms into individual polygons
SELECT ST_AsEWKT((ST_Dump(t.polycoll)).geom) AS geomtextrep
FROM (SELECT ST_Polygonize(geom_4269) AS polycoll
    FROM (SELECT geom_4269 FROM ma.suffolk_edges)
        As foo) AS t;

------------------------
 SRID=4269;POLYGON((-71.040878 42.285678,-71.040943 42.2856,-71.04096 42.285752,
-71.040878 42.285678))
 SRID=4269;POLYGON((-71.17166 42.353675,-71.172026 42.354044,-71.17239 42.354358
,-71.171794 42.354971,-71.170511 42.354855,-71.17112 42.354238,-71.17166 42.353675))

另请参见

ST_BuildAreaST_DumpST_Node