Symbolizing a vector layer
The appearance of the layers on a QGIS map is controlled by its symbology. A layer's symbology includes the renderer and one or more symbols. The renderer provides rules dictating the appearance of symbols. The symbols describe properties, including color, shape, size, and linewidth. In this recipe, we'll load a vector layer, change its symbology, and refresh the map.
Getting ready
Download the following zipped shapefile and extract it to your qgis_data
directory into a folder named ms
from https://geospatialpython.googlecode.com/files/Mississippi.zip.
How to do it...
We will load a layer, add it to the map layer registry, change the layer's color, and then refresh the map. To do this, perform the following steps:
First, using the QGIS Python Console, we must import the
QtGui
library in order to access theQColor
object that is used to describe colors in the PyQGIS API:from PyQt4.QtGui import *
Next, we create our vector layer, as follows:
lyr = QgsVectorLayer("/Users...