[Qgis-user] How to count number of layers loaded in layer panel of QGIS

Ludwig Kniprath ludwig at kni-online.de
Wed Mar 15 10:54:39 PDT 2023


That depends on the kind and state of layers You want to count:


# All layers (as listed in TOC, included: "non-drawable" and invalid layers)

layers = QgsProject.instance().layerTreeRoot().findLayers()
# list-items: "QgsLayerTreeLayer"


# All valid layers (included: "non-drawable"-layers):
layers = QgsProject.instance().mapLayers()
# list-items: layer-id


# Only visible, valid and "drawable" layers:
layers = iface.mapCanvas().layers()
# list-items: layer


for layer in layers:
     print(layer)

print(len(layers))


hth

Ludwig




Am 15.03.23 um 08:42 schrieb Paul N via QGIS-User:
> I want to count number of layer loaded. How to count number of layers 
> loaded in layer panel of QGIS.
>
> Regards.
>
> Paul N
>
> _______________________________________________
> QGIS-User mailing list
> QGIS-User at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user


More information about the QGIS-User mailing list