Graphics Reference
In-Depth Information
Defining the map renderers
Now that we have the map layers, we'll want to set up appropriate symbols and renderers to
draw the vector data onto the map. Let's start by defining a method called setupRen-
derers() , which creates the renderers for our various map layers. Our first renderer will
display the track layer, where we use a QgsRuleBasedRendererV2 object to display
the tracks in different ways depending on the type of track, whether or not the track is open,
and whether it is bidirectional or can only be used in one direction. Here is the relevant
code:
def setupRenderers(self):
root_rule = QgsRuleBasedRendererV2.Rule(None)
for track_type in (TRACK_TYPE_ROAD,
TRACK_TYPE_WALKING,
TRACK_TYPE_BIKE,
TRACK_TYPE_HORSE):
if track_type == TRACK_TYPE_ROAD:
width = ROAD_WIDTH
else:
width = TRAIL_WIDTH
lineColor = "light gray"
arrowColor = "dark gray"
for track_status in
(TRACK_STATUS_OPEN,TRACK_STATUS_CLOSED):
for track_direction in (TRACK_DIRECTION_BOTH,
TRACK_DIRECTION_FORWARD,
TRACK_DIRECTION_BACKWARD):
symbol =
self.createTrackSymbol(width,lineColor,
arrowColor,track_status,track_direction)
expression = ("(type='%s') and " +
"(status='%s') and " +
"(direction='%s')") %
Search WWH ::




Custom Search