I am trying to make a QGIS plugin to change which band in a multi-band data set (netCDF where the band represents time steps) is used for a gray scale rendering. The file works fine with manual changes, but I cannot find how to change it programatically. I have set up a dialog box where I can select which layer to work on:
for layer in self.iface.legendInterface().layers(): # iface.messageBar().pushMessage("Type",layer.name(), level=1, duration=10) if type(layer) is QgsRasterLayer and layer.bandCount()>1: self.layerlist.append(layer) self.dlg.comboBoxLayer.addItem(layer.name())
my QGIS related imports are (as far as I can see)
from qgis.core import * from qgis.utils import *
I have found the attribute setGrayBandName that should select which band to use for presentation, but when I run (knowing 0<=sldValue <=number of bands)
self.dlg.labelStartTime.setText(str(sldValue)) self.activeLayer.setGrayBandName(self.activeLayer.bandName(sldValue)) self.activeLayer.triggerRepaint()
it crashes with "AttributeError: 'QgsRasterLayer' object has no attribute 'setGrayBandName'" - if setGrayBandName does not exist, what should I use then? And why do I find a number of references to it, but none saying that is has been taken out of use? - or have I just misunderstood something? Do I need to import som more modules?
seems like I misunderstood something, I need to set a new gray band on the renderer, i.e.
But, this only works if I start in the console by selecting the layer and then doing
layer=qgis.utils.iface.activeLayer() rndr=layer.renderer() layer.renderer=rndr
Then I can start playing around. If I try to do the rndr=layer.renderer() in the code in the plugin, I am told something like that type of object is not callable...
The present version of the module is available at https://github.com/sickel/TimeStepSelector