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

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

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:

  1. First, using the QGIS Python Console, we must import the QtGui library in order to access the QColor object that is used to describe colors in the PyQGIS API:

    from PyQt4.QtGui import *
  2. Next, we create our vector layer, as follows:

    lyr = QgsVectorLayer("/Users...