-1

This script runs

enter image description here

on only one reference layer and I want it to iterate over all layers in group 1 as a reference layer and name each output layer with the name of its corresponding reference layer and load them in the layer panel.

3

Here is an example that you could adapt to your solution:

  1. List layers that you have in your specific group, in my case it is called plots.
  2. Run your algorithm for each of the layers in your group.
  3. Rename the layer using the layer used in the algorithm, and if you wish you can add the result to the map.
root = QgsProject.instance().layerTreeRoot()

for child in root.children():
  if isinstance(child, QgsLayerTreeGroup):
    if child.name() == "plots": # Group name
        layers_tree = child.findLayers()

for layer_tree in layers_tree:
    layer = layer_tree.layer()
    result = processing.run("native:polygonstolines", {'INPUT':layer,'OUTPUT':'TEMPORARY_OUTPUT'})
    output_layer = result['OUTPUT']
    output_layer.setName('result_{}'.format(layer.name()))  # Rename output layer
    QgsProject.instance().addMapLayer(output_layer)

Regards

1
  • Thanks so much, bro! it works. Jan 15 at 9:08

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