Book Image

Building Mapping Applications with QGIS

By : Erik Westra
Book Image

Building Mapping Applications with QGIS

By: Erik Westra

Overview of this book

Table of Contents (16 chapters)
Building Mapping Applications with QGIS
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Getting Started with QGIS
Index

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 setupRenderers(), 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...