Book Image

QGIS Python Programming Cookbook

Book Image

QGIS Python Programming Cookbook

Overview of this book

Table of Contents (16 chapters)
QGIS Python Programming Cookbook
About the Author
About the Reviewers

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 to the properties of the layer itself. Using a rule-based renderer, this recipe demonstrates how to color code a layer based on an attribute.

Getting ready

You will need to download a zipped shapefile from

Unzip it and place it in the directory named ms in your qgis_data directory.

In this same directory, download and unzip the following shapefile:

Finally, add this shapefile to the directory as well:

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 the frequency of use. Finally, we'll add some other layers to the map for reference. To do this, we need to perform the following steps:

  1. First, we need to...