PostGIS:合并多边形并保持边界

我们正在尝试合并存储在PostGIS 2.1数据库中的两个Multipolygons,而不会丢失每个Multipolygon中包含的边界.

我们的空间数据符合以下标准.

-- 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

如果我们尝试使用以下查询聚合列lower_geom和higher_geom(两者都是MultiPolygon类型),则ST_Union的结果缺少原始多边形的边框.

SELECT
    ST_Union(lower_geom, higher_geom)
FROM
    myTable

为了更清楚,我们添加了一个屏幕截图.在我们期望的结果中,绿色和红色多重多边形应该包含在仍然包含ALL边界的一个新多重多边形中.

有没有人有想法!?

提前致谢,
Cord&马丁

最佳答案 这对我来说对于我扔在一起的几个测试多边形是有用的.它使用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;

将有一种更优雅和有效的方式来编写它,但我想知道这是否适用于您的数据,然后再尝试.

点赞