9

I need to combine 2 large polygon datasets. One of these datasets contains more recent data, so the polygons from this dataset need to be copied into the existing dataset.

There are three different instances where the existing dataset would need to be modified. See below for screenshots and explanations.

(In all screenshots the dashed red outline represents the existing data. The green polygons are new data.)


Situation 1 - Entirely new polygon:

enter image description here

Action - New polygon needs to be added to existing dataset. Polygons that remain the same can be ignored.


Situation 2 - An existing polygon has changed shape:

enter image description here enter image description here enter image description here

Action - Existing polygon(s) needs to be deleted. New polygon then needs to be added to existing dataset.


Situation 3 - Multiple new polygons within an existing polygon

enter image description here

Action - Existing containing/large polygon needs to be deleted. New polygon then needs to be added to existing dataset.


So, my question is; would it be possible to combine these datasets according to the rules above, either in QGIS or PostGIS?

4
  • Are you apposed to using a different process for each situation.
    – Kingfisher
    Commented Nov 30, 2016 at 16:51
  • @Kingfisher Yes I was thinking that might be necessary... Any suggestions welcome!
    – Matt
    Commented Dec 1, 2016 at 9:05
  • How do we know if the polygon is new? You're providing graphics, how about a table definition? Paste the output of \d table Commented Dec 12, 2016 at 22:49
  • @Evan there is nothing currently in the tables to indicate new/old polygons, but it would be simple to add something.
    – Matt
    Commented Dec 13, 2016 at 14:30

1 Answer 1

7
+50

I believe you can do all of this in 2 steps. First, delete all existing polygons where the new polygons table intersects them. In case 1, the existing polygons will not be touched. In cases 2 and 3, all existing polygons that have either grown (and possibly merged into one) or shrunk (and possibly split into smaller ones) will be deleted. Then you simply insert the new polygons into the existing table which will cover cases 2 and 3.

DELETE FROM existing_polygons a USING new_polygons b
WHERE ST_Intersects(a.geom, b.geom);

INSERT INTO existing_polygons 
SELECT * FROM new_polygons;
5
  • Thanks @John, I think you could well be right with this... I'll give it a try
    – Matt
    Commented Dec 12, 2016 at 14:09
  • You'd better make a copy of the existing polygons table first :-) Commented Dec 12, 2016 at 14:14
  • 2
    Is this working? I'm reasonably sure the logic is correct, but I'd be interested to know if I've missed something. Commented Dec 15, 2016 at 14:40
  • It did work well, apart from a few polygons deleted that needed to be kept (but that was only due to messy data), and relatively easily fixed. Thanks John.
    – Matt
    Commented Dec 19, 2016 at 12:19
  • I'm glad. I hope you had a back up of the data. I felt that such nice diagrams deserved a more complex answer, but sometimes things that look complicated aren't. Sadly, the opposite is also very true. Commented Dec 19, 2016 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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