I'd like to know what I'm doing wrong with the merge algorithms in Python.
I have several shapefiles (polygons) ending in 'LNA', 'LNC', 'LDA', and 'LDC', and I'd like to merge them depending on their names (as part of a bigger pyQgis script). The expected output is 4 files, one for each suffix. Here is the code:
import processing
from PyQt4 import QtGui
layer = qgis.utils.iface.mapCanvas().layers()
destpath = str((QtGui.QInputDialog.getText(None, "File path", "without shp suffix"))[0])
for typeCarte in ('LNC', 'LNA', 'LDC', 'LDA'):
layerList = [lyr for lyr in QgsMapLayerRegistry.instance().mapLayers().values() if (lyr.name().endswith(typeCarte) and (lyr.name().startswith('0')))]
processing.runalg("qgis:mergevectorlayers", layerList, destpath)
iface.addVectorLayer(
destpath + ".shp",
typeCarte + '_temp_Fusion',
"ogr")
The processing works but only with the files ending in 'LNC', that is the first item in my list. The LDA_temp_Fusion, LNA_temp_Fusion and so forth are just identical. If I replace now this processing bit with the following line
processing.runalg('saga:mergelayers', layerList,True,True,destpath)
I get the expected result. What is different in those algorithms that make them behave differently? Or is it just me?