Creating a graduated vector layer symbol renderer
A graduated vector layer symbol renderer is the vector equivalent of a raster color ramp. You can group features into similar ranges and use a limited set of colors to visually identify these ranges. In this recipe, we'll render a graduated symbol using a polygon shapefile.
Getting ready
You can download a shapefile containing a set of urban area polygons from https://github.com/GeospatialPython/Learn/raw/master/MS_UrbanAnC10.zip.
Extract this file to a directory named ms
in your qgis_data
 directory.
How to do it...
We will classify each urban area by population size using a graduated symbol, as follows:
First, we import the
QColor
object to build our color range:from PyQt4.QtGui import QColor
Next, we load our polygon shapefile as a vector layer:
lyr = QgsVectorLayer("/qgis_data/ms/MS_UrbanAnC10.shp", "Urban Areas", "ogr")
Now, we build some nested Python tuples that define the symbol...