[Qgis-developer] select a loaded raster layer from qgis legend into python plugin

Matthias Kuhn matthias.kuhn at gmx.ch
Thu Jan 17 07:21:51 PST 2013


Hi Otto,

here a small extract from a plugin I wrote:

Just check for the layer type to only list raster layers

    def initLayerCombobox(self,combobox, default):
        reg = QgsMapLayerRegistry.instance()
        for ( key, layer ) in reg.mapLayers().iteritems():
            combobox.addItem( layer.name(), key )
        
        idx = combobox.findData( default )
        if idx != -1:
            combobox.setCurrentIndex( idx )

Regards

On Thu, 2013-01-17 at 15:54 +0100, Otto Dassau wrote:
> Hi,
> 
> I would like to write a small python plugin to analyse some raster data,
> but I haven't managed to select a loaded layer yet. I searched the howtos and
> found several simple examples about:
> 
> # get the currently active layer
>   layer = self.iface.mapCanvas().currentLayer()
> 
> but as I said I would like to select one of the loaded raster layers from the
> qgis legend using a QtGui.QComboBox in the plugin dialog. At the moment I
> tried the getRasterLayersNames() function I found in several other plugins
> but it seems I am missing something, because the raster layers are not
> selectable. Can someone point me to a simple example to understand the
> general procedure?
> 
> Thanks a lot
> Otto
> 
> 
> 
> 
> 
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer




More information about the Qgis-developer mailing list