1

I made a script that export the SLD stile from the layers in my QGIS project, but... I'm attempting to get the name of the group in which the layer is stored, to use it as a variable for creating a folder to store the sld. How can I do this?

import processing
self=qgis.utils
layers = self.iface.mapCanvas().layers()

for layer in layers:
    name = layer.name()
    pathsld = 'C:/Style/SLD/'+str(name)+'.sld'  
    layer.saveSldStyle(pathsld)

1 Answer 1

4

You can get the current group of the layer by making each layer selected in turn.

layers = iface.mapCanvas().layers()
layer_tree_view = iface.layerTreeView()
for layer in layers:
    layer_tree_view.setCurrentLayer(layer)
    print(layer_tree_view.currentGroupNode().name())

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.