PostGIS: merging multi-terminal networks and preserving borders

We are trying to combine the two Multipolygons that are stored in our PostGIS 2.1 database without losing the boundaries that are contained in each Multipolygon.

Our spatial data meets the following criteria.

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

If you then try to combine the columns lower_geom and higher_geom (both types of MultiPolygon) with the following query, the result of ST_Union does not have the boundaries of the original polygons.

SELECT
    ST_Union(lower_geom, higher_geom)
FROM
    myTable

To make this clearer, we added a screenshot. In our desired result, both green and red multipolygons should be contained in ONE new polygons still containing ALL borders.

enter image description here

Does anyone have an idea !?

Thanks in advance, Cord and Martin

+4
1

, . 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;

, , , .

+2

Source: https://habr.com/ru/post/1544332/


All Articles