Cor*_*yer 5 postgis spatial qgis postgresql-9.3
我们正在尝试合并存储在 PostGIS 2.1 数据库中的两个多边形,而不会丢失每个多边形中包含的边界。
我们的空间数据符合以下标准。
-- Check whether the polygons share points (boundaries?)
-- ST_Intersects:
-- Returns TRUE if the Geometries/Geography "spatially intersect in 2D" - (share any portion of space)
-- and FALSE if they don't (they are Disjoint).
ST_Intersects(higher_geom,lower_geom) = TRUE
-- ST_Crosses:
-- Returns TRUE if the supplied geometries have some, but not all, interior points in common.
ST_Crosses(higher_geom,lower_geom) = FALSE
-- Since ST_Crosses would return FALSE if the polygons have all interior points in common
-- we have to ensure this is not the case
ST_Within(higher_geom,lower_geom) = FALSE
Run Code Online (Sandbox Code Playgroud)
如果我们随后尝试使用以下查询聚合 lower_geom 和 upper_geom 列(均为 MultiPolygon 类型),则 ST_Union 的结果缺少原始多边形的边界。
SELECT
ST_Union(lower_geom, higher_geom)
FROM
myTable
Run Code Online (Sandbox Code Playgroud)
为了更清楚地显示,我们添加了屏幕截图。在我们想要的结果中,绿色和红色多边形都应包含在一个仍包含所有边界的新多边形中。

有人有想法吗!?
提前致谢,科德和马丁
这对我来说适用于我组合在一起的一些测试多边形。它使用 ST_Dump 技巧来取消合并由内部查询生成的几何集合(别名为表 c),然后使用 ST_Multi(ST_Collect(geom...) 重新收集几何图形。内部查询组合了两组几何图形的交集。具有交集和并集差异的几何。
select ST_multi(ST_Collect(d.geom))
from (select (ST_Dump(c.geom)).geom
from (select ST_Collect(ST_Intersection(a.geom, b.geom),
ST_SymDifference(ST_Intersection(a.geom, b.geom),
ST_Union(a.geom, b.geom))) as geom
from lower_geom a, higher_geom b)
as c)
as d;
Run Code Online (Sandbox Code Playgroud)
将会有一种更优雅和更有效的方法来编写它,但在尝试之前我想知道这是否适用于您的数据。