[QGIS-Developer] PyQGIS: Check if layer is already loaded?

Siki Zoltan siki at agt.bme.hu
Sun Jun 4 10:45:44 PDT 2017


Dear Magnus.

you can iterate through the layers:

for lay in QgsMapLayerRegistry.instance().mapLayers().values():
     if lay.name() == your_layer_name:
         your layer is loaded


Regards,
Zoltan

On Sun, 4 Jun 2017, Magnus Homann wrote:

> I'm writing a plugin that adds feature to a SHP-layer, specified as a 
> filename.
> If the layer already is loaded in Qgis, I want to check for and use the 
> loaded
> layer instead of creating a new from the same SHP-file.
>
> Is this even possible?
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


More information about the QGIS-Developer mailing list