9

Can a memory layer be used as an input and/or output with runalg?

With runandload I get this to work:

 processing.runandload("qgis:mergevectorlayers","memory:bufferOne", "memory:bufferTwo", r"memory:merged")
 processing.runandload("qgis:dissolve", r"memory:merged", True, '', r"D:\PythonTesting\dissolved.shp")

Parameter 2 and 3 are the input layers, which are in memory already, and parameter 3 is the output layer, which is written into memory and used in the following tool (Dissolve). This works fine, but when I try to use the same logic with runalg, then my merged layer in memory does not seem to be created, as the Dissolve tool never runs. The following, for example, would not work:

 processing.runalg("qgis:mergevectorlayers","memory:bufferOne", "memory:bufferTwo", r"memory:merged")
 processing.runandload("qgis:dissolve", r"memory:merged", True, '', r"D:\PythonTesting\datenschrott\dissolved.shp")

Can I assume that runalg either does not accept layers that are in memory or that it cannot output any?

4

Not completely sure why your method doesn't work but another method is to instead use None when using runalg as this will also create an output in memory. Below I defined the first process as output_0 and called the result of this as input to the second process:

output_0 = processing.runalg("qgis:mergevectorlayers",["memory:bufferOne", "memory:bufferTwo"], None)
processing.runandload("qgis:dissolve", output_0['OUTPUT'], True, '', r"D:\PythonTesting\dissolved.shp")

Result:

Result


Tested on QGIS 2.16.0-Nødebo with Processing plugin v2.12.2.

Note that qgis:mergevectorlayers now requires a list of input layers.

1

http://gis.stackexchange.com/q/76594/22646 sheds more light on runalg, runandload and memory layer. According to http://gis.stackexchange.com/a/184802, the way of referring to the resulting memory layer depends on the Processing version.

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.