[GIS] pyqgis: AttributeError: ‘QgsRasterLayer’ object has no attribute ‘drawingStyle’

pyqgis

I am following http://www.qgis.org/en/docs/pyqgis_developer_cookbook/intro.html. In python console after a raster layer is loaded to a variable "rlayer"

>>>rlayer
  <qgis.core.QgsRasterLayer object at 0x113faadf8>

>>>rlayer.drawingStyle()
  Traceback (most recent call last):
         File "<input>", line 1, in <module>
         AttributeError: 'QgsRasterLayer' object has no attribute 'drawingStyle'

>>>rlayer.setDrawingStyle(QgsRasterLayer.SingleBandPseudoColor)
  Traceback (most recent call last):
         File "<input>", line 1, in <module>
         AttributeError: type object 'QgsRasterLayer' has no attribute 'SingleBandPseudoColor'


>>>rlayer.setColorShadingAlgorithm(QgsRasterLayer.PseudoColorShader)
   Traceback (most recent call last):
         File "<input>", line 1, in <module>
         AttributeError: 'QgsRasterLayer' object has no attribute 'setColorShadingAlgorithm'

what did I do wrong?

Best Answer

I used an alternative method which might help you.

In stead of changing properties of your raster layer, you can assign a prepared style to a layer:

rlayer.loadNamedStyle("c:/some/folder/tree/style01.qml")
# and look at canvas if it did what you want
QgsMapLayerRegistry.instance().addMapLayer(rlayer)
Related Question