3

For a merge operation I need a list of all my layers in the TOC with path and filename. How can I achieve that?

layers = QgsProject.instance().mapLayers() # dictionary
myLyrList[]
for layer in layers.values():
   print(layer.name())
#Here I need a List of the my layers in the toc with the path and the filename
processing.run("native:mergevectorlayers", {'LAYERS':['/home/lissiklaus/Downloads/2.shp|layername=2','/home/lissiklaus/Downloads/3.shp'],'CRS':QgsCoordinateReferenceSystem('EPSG:31468'),'OUTPUT':'TEMPORARY_OUTPUT'})

1 Answer 1

3

You can do that with following modifications in your script.

layers = QgsProject.instance().mapLayers() # dictionary

for layer in layers.values():
   print(layer.name())

list_layers = list(layers.values())

crs = list_layers[0].crs()

#Here I need a List of the my layers in the toc with the path and the filename
processing.runAndLoadResults("native:mergevectorlayers", 
                             {'LAYERS':list_layers,
                             'CRS':crs,
                             'OUTPUT':'TEMPORARY_OUTPUT'})

I tried above script out and it worked as expected.

2
  • just excat what I need gracias!
    – klaus k.
    Commented Oct 6, 2019 at 19:19
  • So, can you mark this answer as accepted? Thanks.
    – xunilk
    Commented Oct 6, 2019 at 20:00

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.