1

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?

2

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)
2

The problem is that the method is outdated since qgis 2.10 (or so). According to the QGIS API you directly have to use the .setRenderer() method.

0

Setting the drawing style works with :

rlayer.setDrawingStyle("SingleBandPseudoColor")

But i'm still struggling with the other errors ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.