Graphics Reference
In-Depth Information
(track_type,track_status,
track_direction)
rule =
QgsRuleBasedRendererV2.Rule(symbol,filterExp=expression)
root_rule.appendChild(rule)
symbol = QgsLineSymbolV2.createSimple({'color' :
"black"})
rule = QgsRuleBasedRendererV2.Rule(symbol,
elseRule=True)
root_rule.appendChild(rule)
renderer = QgsRuleBasedRendererV2(root_rule)
self.trackLayer.setRendererV2(renderer)
As you can see, we iterate over all the possible track types. Based on the track type, we
choose a suitable line width. We also choose a color to use for the line and the arrow-
heads—for now, we're simply using the same color for every type of track. We then iterate
over all the possible status and direction values, and call a helper method named cre-
ateTrackSymbol() to create a suitable symbol for this track type, status, and direc-
tion. We then create a QgsRuleBasedRendererV2.Rule object that uses that sym-
bol for those tracks with the given type, status, and direction. Finally, we define an "else"
rule for the renderer, displaying the track as a simple black line if the track doesn't have
any of the expected attribute values.
Our remaining map layers will use straightforward line or marker symbols to display the
shortest path, and the starting and ending points. Here's the remainder of the setupRen-
derers() method, which defines these map renderers:
symbol = QgsLineSymbolV2.createSimple({'color' :
"blue"})
symbol.setWidth(ROAD_WIDTH)
symbol.setOutputUnit(QgsSymbolV2.MapUnit)
renderer = QgsSingleSymbolRendererV2(symbol)
self.shortestPathLayer.setRendererV2(renderer)
symbol = QgsMarkerSymbolV2.createSimple(
{'color' : "green"})
Search WWH ::




Custom Search