Graphics Reference
In-Depth Information
Note
You might be wondering why all these classes have "V2" in their name. This is a
historical quirk of QGIS. Earlier versions of QGIS supported both an "old" and a
"new" system of rendering, and the "V2" naming refers to the new rendering sys-
tem. The old rendering system no longer exists, but the "V2" naming continues to
maintain backward compatibility with existing code.
Internally, symbols are rather complex, using "symbol layers" to draw multiple elements
on top of each other. In most cases, however, you can make use of the "simple" version of
the symbol. This makes it easier to create a new symbol without having to deal with the
internal complexity of symbol layers. For example:
symbol = QgsMarkerSymbolV2.createSimple({'width' : 1.0,
'color' :
"255,0,0"})
While symbols draw the features onto the map, a renderer is used to choose which symbol
to use to draw a particular feature. In the simplest case, the same symbol is used for every
feature within a layer. This is called a single symbol renderer , and is represented by the
qgis.core.QgsSingleSymbolRenderV2 class. Other possibilities include:
Categorized symbol renderer
( qgis.core.QgsCategorizedSymbolRendererV2 ): This renderer
chooses a symbol based on the value of an attribute. The categorized symbol ren-
derer has a mapping from attribute values to symbols.
Graduated symbol renderer
( qgis.core.QgsGraduatedSymbolRendererV2 ): This type of renderer
uses ranges of attribute values, and maps each range to an appropriate symbol.
Using a single symbol renderer is very straightforward:
symbol = ...
renderer = QgsSingleSymbolRendererV2(symbol)
layer.setRendererV2(renderer)
To use a categorized symbol renderer, you first define a list of
qgis.core.QgsRendererCategoryV2 objects, and then use that to create the ren-
derer. For example:
Search WWH ::




Custom Search