2

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

1 Answer 1

3

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", 
{'INPUT':blue,
'OVERLAY':grid,
'OUTPUT':'TEMPORARY_OUTPUT'})

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

processing.run("native:union", 
{'INPUT':difference,
'OVERLAY':blue,
'OUTPUT':path_to_output})
0

Your Answer

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

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