1

We have areas (merged polygons) with an unique id in a PostGIS database. The unique id (serial) is referenced by other datasets (actions that happen in these areas). Sometimes we need to append a few new polygons to the existing areas. When we try to merge them simply together, this doesn't work because the original area (with id) will be deleted to create a new one, but this isn't possible when the old area has actions that rely on the id. Is there no other possibility to append the new polygons to the old one without changing (deleting) the original id? Just like updating the geometry of the dataset.

  • what's wrong with UPDATE? you can e.g. SET geom = ST_Union(geom, <NEW.geom>)? – geozelot Apr 3 '19 at 7:42
  • Ok, this would work in PostGIS, but as fas as I see there is no such function in the QGis GUI. The guys who are working on this are used to work with QGIS, but not with PostGIS-queries. – geom Apr 3 '19 at 12:56
  • Using a temporary scratch layer, you can add both polygons. Merge them together and copy the new geometry to the one in the database. This means a lot of steps but is it worth to do? – PieterB Apr 3 '19 at 13:02
  • 1
    then please add the exact workflow; if you simply edit layers, QGIS will run simple UPDATEs and all should work as expected. if anything else than editing is involved (creating layers or sth.), a more complex solution is required (e.g. working with updateable Views) – geozelot Apr 3 '19 at 13:22
  • To add just a new parcel to an existing area (already merged parcels), I can use the Add new part Tool from the Advanced Digitizing Tools in QGIS. I can digitize the new polygon. But often we have to add a bunch of new parcels, that are already digitized, so that we could copy the geometry to add it to the existing one. but there is no tool that allows to append new areas (from copy-paste) to existing ones beside the Merge-tool with the problems described above. – geom Apr 3 '19 at 21:33
-1

Just to explain a bit further:

Usually we copy the NewPolygons fron another layer, merge them together on a temporary scratch layer => MergedPolygons and then add these to the layer with the ExistingPolygons.

We can then merge the MergegPolygons together with an ExistingPolygon. The goal is to add the geometry of the MergedPolygons to the one of the ExistingPolygon without using the merge function, since this function creates an NewPolygon and deletes the MergedPolygons and the ExistingPolygon. This doesn't work when the ExistingPolygon is already refered by other datasets that rely on it (1:n-relation).

So for us a Gui would be nice that would work the opposite way as the 'delete part of multipolygon'. Select ExistingPolygon + select MergedPolygons (on the same layer or on scratch layer) => Extend the geometry of the ExistingPolygon with the geometry of the selected MergedPolygon.

In Postgis this work:

With sq AS (SELECT the_geom 
FROM scratchLayer 
WHERE scratchLayer.id = SELECTED ID) -- I know that SELECTED ID doesn't exist in SQL 

UPDATE existingLayer
SET the_geom = st_union(existingLayer.the_geom, sq.the_geom)
FROM sq
Where existingLayer.id = SELECTED ID  -- I know that SELECTED ID doesn't exist in SQL
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.