[Qgis-developer] Determine whether layer is OpenLayers layer

Martin Dobias wonder.sk at gmail.com
Wed Jul 16 06:16:40 PDT 2014

Hi Tom

On Wed, Jul 16, 2014 at 3:08 PM, Tom Chadwin <tom.chadwin at nnpa.org.uk> wrote:
> In a plugin, we currently loop through all layers in qgis.utils.iface.mapCanvas().layers. We determine whether a layer is eg WFS by using QgsVectorLayer.providerType(). However, if OpenLayers plugin layers are present, this fails:
> AttributeError: 'OpenlayersLayer' object has no attribute 'providerType'
> How should I broaden out the detection of type of layer to determine whether it is such an OpenLayers layer? I will also then probably want to determine which OpenLayers layer it is (eg OSM, Google, etc), but for the moment, that can wait.
> Is there documentation of the OpenLayers plugin suitable for working with it in plugin development? An API?

Use QgsMapLayer.type() method - it will return one of three values:
- QgsMapLayer.VectorLayer
- QgsMapLayer.RasterLayer
- QgsMapLayer.PluginLayer

OpenLayers is plugin layer (providers are used just in vector and
raster layers). Type of the plugin layer can be detected from
pluginLayerType() method - it will return identifier of that plugin
layer as used in QgsPluginLayerRegistry.


More information about the Qgis-developer mailing list