Piping output of one processing algorithm as input into another algorithm in QGIS Processing script?
I created a processing script in QGIS 2.18 that connects two processing algorithms (first clip and than dissolve). The output vector from the clip is supposed to be an input into the dissolve.
The code of my processing script is provided here:
##input_layer=vector
##clip_layer=vector
##clipped_layer=output vector
##processed_layer=output vector
clip_area = processing.runalg("qgis:clip", input_layer, clip_layer,
clipped_layer)
fin_area = processing.runalg("qgis:dissolve", clip_area, "true", None,
processed_layer)
The screeshot of processing script UI when I try to run it is below:
Both of the algorithms work correctly standalone, but when I try to pipe them it does not work as intended. I only get clipped_layer as output and the following error notification in Python Console:
There are several questions adressing related issues like Pipe custom processing algorithm output into another in QGIS 3.0 but none really answers my question.
Does anybody know how to correctly pipe algorithms in the example processing script provided above?
I know it could be solved by using Processing Modeler but since I plan to expand the script further, please, don ́t suggest this as solution.
1 Answer 1
The processing.runalg() return a python dictionary with one record: 'OUTPUT' is the key and the value is the absolute path at result layer.
So in the next algorithm instead of the parameter clip_area
you have to use clip_area['OUTPUT']
-
Yes, you need to specify the 'OUTPUT' with the output layer. This worked for me. Thanks Does this work for all kind of algorithms with spatial outputs?Yanic– Yanic2018年04月23日 07:48:04 +00:00Commented Apr 23, 2018 at 7:48
-
1Sometimes changes the key string value
'OUTPUT'
, you have to print the dictionary result to know it... Take care that all of this is heavily changed in QGIS 3.0Oscar Campo– Oscar Campo2018年04月23日 08:26:31 +00:00Commented Apr 23, 2018 at 8:26
fin_area = processing.runalg("qgis:dissolve", clip_area['OUTPUT'], "true", None, processed_layer)