From some other posts I found that i can determine a layers visiblity by something like

#assume lyr_name the layers name to determine visibity for
l = QgsMapLayerRegistry.instance().mapLayersByName(lyr_name)[0]
vis = QgsProject.instance().layerTreeRoot().findLayer(l.id()).isVisible()

Apart from this being put in a method like

def isVis(lyr_name):
    l = QgsMapLayerRegistry.instance().mapLayersByName(lyr_name)[0]
    return QgsProject.instance().layerTreeRoot().findLayer(l.id()).isVisible()

Is this the recommendend way to check if a layer is visible, whichs name is known or is there a more simpler approach?

  • 1
    Could you please provide some context as to what you are trying to achieve? :) – Joseph Jan 19 '18 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.