I'm trying to automate a procedure which involves a Dissolve. I've got the layer stored as a variable (layer_shp
) and am trying to dissolve it through Python, as such:
dissolve_process = processing.run("gdal:dissolve", layer_shp, "", "memory")
layer_dissolve_shp = dissolve_process["OUTPUT"]
layer_dissolve_shp.commitChanges()
QgsProject.instance().addMapLayer(layer_dissolve_shp)
This is giving us the following errors:
After the dissolve_process = processing.run("gdal:dissolve", layer_shp, "", "memory")
:
Traceback (most recent call last):
File "C:\PROGRA~1\QGIS3~1.4\apps\Python37\lib\code.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "C:/PROGRA~1/QGIS3~1.4/apps/qgis-ltr/./python/plugins\processing\tools\general.py", line 105, in run
return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback, context)
File "C:/PROGRA~1/QGIS3~1.4/apps/qgis-ltr/./python/plugins\processing\core\Processing.py", line 130, in runAlgorithm
context = dataobjects.createContext(feedback)
File "C:/PROGRA~1/QGIS3~1.4/apps/qgis-ltr/./python/plugins\processing\tools\dataobjects.py", line 72, in createContext
context.setFeedback(feedback)
TypeError: QgsProcessingContext.setFeedback(): argument 1 has unexpected type 'str'
Then, of course, when I try and commit changes:
AttributeError: 'str' object has no attribute 'commitChanges'
Think this should be quite an easy one but I'm not finding much about doing a dissolve. This isn't dissolving on a field, and I'm wanting it dissolved to memory and then adding into the project. This is QGIS 3.4.5
EDIT - this is the code I ended up using:
layer_dissolve_shp = processing.run("native:dissolve", {'INPUT':'Spray_SHP','FIELD':[],'OUTPUT':'memory:'})["OUTPUT"]
QgsProject.instance().addMapLayer(layer_dissolve_shp)
The layer exists as a memory layer on the QGIS layers list as "Spray_SHP" (note - this is not a shapefile - we're doing everything in memory and not saving to disk). This will just get that layer and dissolve it to layer_dissolve_shp, then add it as 'output'.