Graphics Reference
In-Depth Information
To set the drawing style, use the layer.setDrawingStyle() method, passing in a
string that contains the name of the desired drawing style. You will also need to call the
various setXXXBand() methods, as described in the preceding table, to tell the raster
layer which bands contain the value(s) to use to draw each pixel.
Note that QGIS doesn't automatically update the map when you call the preceding func-
tions to change the way the raster data is displayed. To have your changes displayed right
away, you'll need to do the following:
1. Turn off raster image caching. This can be done by calling lay-
er.setImageCache(None) .
2. Tell the raster layer to redraw itself, by calling layer.triggerRepaint() .
Accessing raster data
As with vector-format data, you can access the underlying raster data via the data pro-
vider's identify() method. The easiest way to do this is to pass in a single coordinate
and retrieve the value or values at that coordinate. For example:
provider = layer.dataProvider()
values = provider.identify(QgsPoint(x, y),
QgsRaster.IdentifyFormatValue)
if values.isValid():
for band,value in values.results().items():
...
As you can see, you need to check whether the given coordinate exists within the raster
data (using the isValid() call). The values.results() method returns a diction-
ary that maps band numbers to values.
Using this technique, you can extract all the underlying data associated with a given co-
ordinate within the raster layer.
Tip
You can also use the provider.block() method to retrieve the band data for a large
number of coordinates all at once. We will look at how to do this later in this chapter.
Search WWH ::




Custom Search