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:

  1. First, we import the QColor object to build our color range:
            from PyQt4.QtGui import QColor 
    
  2. Next, ...

Get QGIS Python Programming Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.