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?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Mar 4, 2016 at 16:50
1

2 Answers 2

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.

answered Aug 12, 2016 at 12:40
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.

answered Nov 18, 2017 at 22:17

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.