gpt4 book ai didi

postgis - 如何将相邻多边形合并为 1 个多边形并保留最小/最大数据?

转载 作者:行者123 更新时间:2023-12-02 16:01:44 24 4
gpt4 key购买 nike

我在 PostGIS 中有以下多边形

enter image description here

每个多边形都有带有“数据”值的字段。我想自动合并彼此接触的多边形:1-2和3-4-5-6-7

另外,如果可能的话,我希望将每个多边形的列中的最小/最大值保留到新的多边形

Id  Data    Geom
1 8.45098 MULTIPOLYGON(((178253.411393551 665205.232423685,178248.411393552 665205.232423685,178248.411393552 665210.232423684,178253.411393551 665210.232423684,178253.411393551 665205.232423685)))
2 10.7918 MULTIPOLYGON(((178258.411393551 665205.232423685,178253.411393551 665205.232423685,178253.411393551 665210.232423684,178258.411393551 665210.232423684,178258.411393551 665205.232423685)))
3 10.7918 MULTIPOLYGON(((178263.411393552 665185.232423682,178258.411393551 665185.232423682,178258.411393551 665190.232423685,178263.411393552 665190.232423685,178263.411393552 665185.232423682)))
4 10.4139 MULTIPOLYGON(((178268.411393553 665185.232423682,178263.411393552 665185.232423682,178263.411393552 665190.232423685,178268.411393553 665190.232423685,178268.411393553 665185.232423682)))
5 7.448 MULTIPOLYGON(((178263.411393552 665180.232423684,178258.411393551 665180.232423684,178258.411393551 665185.232423682,178263.411393552 665185.232423682,178263.411393552 665180.232423684)))
6 10.2318 MULTIPOLYGON(((178268.411393553 665180.232423684,178263.411393552 665180.232423684,178263.411393552 665185.232423682,178268.411393553 665185.232423682,178268.411393553 665180.232423684)))
7 10.998 MULTIPOLYGON(((178263.411393552 665175.232423685,178253.411393551 665175.232423685,178253.411393551 665180.232423684,178258.411393551 665180.232423684,178263.411393552 665180.232423684,178263.411393552 665175.232423685)))
8 10.7548 MULTIPOLYGON(((178263.411393552 665175.232423685,178253.411393551 665175.232423685,178253.411393551 665180.232423684,178258.411393551 665180.232423684,178263.411393552 665180.232423684,178263.411393552 665175.232423685)))

最简单的方法是什么(我对 QGIS/ArcMap 知之甚少,对 PostGIS 有更好的了解)?

最佳答案

我能弄清楚如何做到这一点的唯一方法是在 CTE 中创建联合几何图形表,使用 ST_Dump 生成单独的多边形(即 1-2 和 3-4 -5-6 在你的问题中),然后从原始表(我将其称为多边形,因为你没有指定名称)中选择数据属性的最大值和最小值,它们与新的联合几何图形相交,并且按相同的新联合几何图形分组。

WITH geoms (geom) as 
(SELECT (ST_Dump(ST_Union(geom))).geom from polygons)
SELECT max(data), min(data), g.geom
FROM polygons p, geoms g
WHERE St_Intersects(s.geom, g.geom)
GROUP BY g.geom;

如果要将其保存到新表中,请在 WITH 前面添加 CREATE TABLE new_table AS。可能有更有效的方法,但这是有效的。在您的问题中,您的输入多边形是 MutliPolygons,因此如果您也希望在输出中使用它,请在新的联合几何体前面添加 ST_Multi 。将所有这些放在一起,您会得到如下内容:

CREATE TABLE Unioned_geometries AS
WITH geoms (geom) as
(SELECT (ST_Dump(ST_Union(geom))).geom from polygons)
SELECT max(data), min(data), ST_Multi(g.geom)
FROM polygons p, geoms g
WHERE St_Intersects(s.geom, g.geom)
GROUP BY g.geom;

关于postgis - 如何将相邻多边形合并为 1 个多边形并保留最小/最大数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27081061/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com