我首先通过将ST_Node与ST_Collect结合使用来将这些行转换为MultiLinestring中的一组结点线串,从而完成了这项工作。
就像在ST_Node的文档中说的那样:
使用最少数量的节点将一组线串完全节点化,同时保留所有输入节点。
这就是说,所有线串都以所有可能的组合进行组合,以构成与多边形外环等效的线。而如果您尝试ST_Polygonize一组LineString,但它们本身都不描述多边形,则只需将LineString返回即可。因此,这可行:
WITH multi(geom) AS (
SELECT ST_Node(ST_Collect(geom))
FROM leyenda_digitalizar00
)
SELECT ST_AsText( (ST_Dump(ST_Polygonize(geom))).geom )
FROM multi;
如果仅运行其中的第一部分,即CTE multi,则输出如下所示:
多线串((204.5 69.9000000000004,204.5 69.9000000000004),(204.5 68.9,205.4 68.9),(204.5 68.9,204.5 69,204.5 69.1,204.5 69.2,204.5 69.3,204.5 69.4,204.5 69.5,204.5 69.6,204.5 69.7,204.5 69.8,204.5 69.5,204.5 69.1 204.5 69.9000000000004),(209.5 68.9,209.5 68.8,209.5 68.7,209.5 68.6,209.5 68.5,209.5 68.4,209.5 68.3,209.5 68.2,209.5 68.1,209.5 68,209.5 67.9,209.5 67.8,209.5 67.7,209.5 67.6,209.5 67.5,209.5 67.4 ,209.5 .......
现在,当您现在将此MultiLinestring输入ST_Polygonize时,它可以按预期工作,例如,
聚(((205.4 68.9,204.5 68.9,204.5 69,204.5 69.1,204.5 69.2,204.5 69.3,204.5 69.4,204.5 69.5,204.5 69.6,204.5 69.7,204.5 69.8,204.5 69.9,204.5 69.9000000000004,205.4 69.9,205.4 69.3,205.4 68.9))
聚((204.5 69.9000000000004,204.5 70,204.5 70.1,204.5 70.2,204.5 70.3,204.5 70.4,206.8 70.4,209.5 70.4,209.5 70.3,209.5 70.2,209.5 70.1,209.5 70,209.5 69.9,205.4 69.9,204.5 69.9000000000004)
多边形((206.8 70.4,204.5 70.4,204.5 70.5,204.5 70.6,204.5 70.7,204.5 70.8,204.5 70.9,204.5 71,204.5 71.1,204.5 71.2,204.5 71.3,204.5 71.4,206.8 71.4,206.8 70.4)
显然,ST_AsText仅用于说明,如果您也需要路径ID,则必须进行调整。
关键要点在于,ST_Polygonize期望已描述多边形轮廓的线串,这就是ST_Node(ST_Collect(....