I'm trying to write python script in QGIS to merge layers having the same name.
To do that I specify the name of layer in the script, so all layers having this name, will be merged. However, since I have a lot of names this is not practical. I tried to convert the names type from unicode to list to be able to iterate in the list of names.
In this script, I specify layer name. I want to iterate over all names and compare them to finally merge layers having same name.
import qgis.core
import processing
def __init__(self, iface):
self.iface = iface
lyr_list=[]
count=1
layers=iface.mapCanvas().layers()
for i in layers:
if i.name() == 'layer_name':
lyr_list.append(i)
processing.runandload("qgis:mergevectorlayers", lyr_list, "memory:merged")