Merging vector layers via python in QGIS 2.18.1
Yes, if you type in the following code in the Python Console, the input layer parameter now incorporates multiple layers:
>>>import processing
>>>processing.alghelp("qgis:mergevectorlayers")
ALGORITHM: Merge vector layers
LAYERS <ParameterMultipleInput>
OUTPUT <OutputVector>
So one way of resolving this is to add both layers into the input parameter and split them:
processing.tools.general.runalg("qgis:mergevectorlayers", layer1 + ";" + layer2, output)
Since trying above answer causes an exception (l1
and l2
are both of type QgsVectorLayer
, QGIS 2.18.17 Python console) for me
import processing
[...]
processing.runalg('qgis:mergevectorlayers', l1 + ";" + l2, None)
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'QgsVectorLayer' and 'str'
I've been trying
>>> merged = processing.runalg('qgis:mergevectorlayers', [l1, l2], None)
>>> merged['OUTPUT']
u'C:\\Users\\Jochen\\AppData\\Local\\Temp\\processing30eee19448ef42a497403dd3660cafcf\\82e112158f194f59a53e18d5020a9a9d\\OUTPUT.shp'
successfully.
So passing <ParameterMultipleInput>
as a python list is a solution to this.