-
Book Overview & Buying
-
Table Of Contents
QGIS Python Programming Cookbook
By :
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.
You can download a shapefile containing a set of urban area polygons from https://geospatialpython.googlecode.com/files/MS_UrbanAnC10.zip.
Extract this file to a directory named ms in your qgis_data directory.
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 graduation. Each item in the tuple contains a range label, range start...
Change the font size
Change margin width
Change background colour