Rendering map layers based on rules
Rendering rules provide a powerful way to control how and when a layer is displayed relative to other layers or properties of the layer itself. This recipe demonstrates how to use a rule-based renderer to color code a layer based on an attribute.
Getting ready
You will need to download a zipped shapefile from the following URL:
https://github.com/GeospatialPython/Learn/raw/master/ms_rails_mstm.zip
Unzip it and place it in directory named ms
in your qgis_data
directory.
In that same directory, download and unzip the following shapefile:
https://github.com/GeospatialPython/Learn/raw/master/Mississippi.zip
Finally, add this shapefile to the directory as well:
https://github.com/GeospatialPython/Learn/raw/master/jackson.zip
How to do it...
We will set up a railroad layer; then, we'll set up our rules as Python tuples to color code it, based on frequency of use. Finally, we'll add some other layers to the map for reference.
- First, we need the
QtGui
library...