I have two overlapping polygon vector layers. enter image description here

I want to combine these two layers into one vector layer, but I don't want to keep overlaying parts - the blue layer is of higher importance (weight), so I want to keep only blue features and if there is no blue feature, than keep the red polygon (or said in other words: fill the empty space in blue layer into the boundary of red polygon - the red layer doesn't hold important information, I use it only to know the boundary box to fill).

I know how to do it in multiple steps: use Difference tool (to clip out the blue parts from red polygon) and then Union to combine both layers, but is there please any way how to do it in only one step?

I want to implement it into Python (PyQGIS) script and I don't want to create unnecessary files that take up space and increase computing time.

processing.run("native:red", {'INPUT':blue,'OVERLAY':grid,'OUTPUT':difference})
processing.run("native:union", {'INPUT':difference,'OVERLAY':blue,'OVERLAY_FIELDS_PREFIX':'','OUTPUT':combined_layer})

I do not know if there is a way to do it in one step. However, as workaround, you can use the memory layer option for your first processing tool which will be saved temporarily and you can use this memory layer in the second processing tool.

res1= processing.run("native:difference", 

difference = res1['OUTPUT'] # this is a memory layer (temporary)


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.