3

I would like to use the tool "Union" to union 3 different layers. This tool unfortunately can union only 2 layers so I have to run it twice.

First I run it to union the layers "Layer1" and "Layer2"

param_union = {
    'INPUT' : QgsProcessingFeatureSourceDefinition('X:/HoWGK.gpkg|layername=Layer1', selectedFeaturesOnly=False, featureLimit=-1, flags=QgsProcessingFeatureSourceDefinition.FlagOverrideDefaultGeometryCheck, geometryCheck=QgsFeatureRequest.GeometrySkipInvalid),
    'OUTPUT' : "memory:myUnionLayer1",
    'OVERLAY' : QgsProcessingFeatureSourceDefinition('X:/HoWGK.gpkg|layername=Layer2', selectedFeaturesOnly=False, featureLimit=-1, flags=QgsProcessingFeatureSourceDefinition.FlagOverrideDefaultGeometryCheck, geometryCheck=QgsFeatureRequest.GeometrySkipInvalid),
    'OVERLAY_FIELDS_PREFIX' : '' }
 
union_1 = processing.run("qgis:union", param_union)

Then, I'd like to take the output layer created as temporary/memory layer to union it with a 3rd layer "Layer3"

param_union = {
    'INPUT' : QgsProcessingFeatureSourceDefinition("memory:myUnionLayer1", selectedFeaturesOnly=False, featureLimit=-1, flags=QgsProcessingFeatureSourceDefinition.FlagOverrideDefaultGeometryCheck, geometryCheck=QgsFeatureRequest.GeometrySkipInvalid),
    'OUTPUT' : "memory:myUnionLayer2",
    'OVERLAY' : QgsProcessingFeatureSourceDefinition('X:/HoWGK.gpkg|layername=Layer3', selectedFeaturesOnly=False, featureLimit=-1, flags=QgsProcessingFeatureSourceDefinition.FlagOverrideDefaultGeometryCheck, geometryCheck=QgsFeatureRequest.GeometrySkipInvalid),
    'OVERLAY_FIELDS_PREFIX' : '' }
 
union_2 = processing.run("qgis:union", param_union)

But I got the error message: "Could not load source layer for INPUT: memory:myUnionLayer1 not found"

How can I access my temporary layer to use it in the algorithm?

1 Answer 1

1
union_1 = processing.run("qgis:union", param_union)

Should be

union_1 = processing.run("qgis:union", param_union)['OUTPUT']

Or union1 is a dictionary, not a layer

2
  • Hi! Thanks, I changed that but it didn't solve the problem...
    – SaskiaG
    Apr 27, 2021 at 8:36
  • There is a new plugin named “Multi Union”, that works fine with polygon vector layers, no matter they are permanent or temporary.
    – MLourdes
    Nov 18 at 21:20

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.