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

Creating a complex vector layer symbol

The true power of QGIS symbology lies in its ability to stack multiple symbols in order to create a single complex symbol. This ability makes it possible to create virtually any type of map symbol you can imagine. In this recipe, we'll merge two symbols to create a single symbol and begin unlocking the potential of complex symbols.

Getting ready

For this recipe, we will need a line shapefile, which you can download and extract from

Add this shapefile to a directory named shapes in your qgis_data directory.

How to do it…

Using the QGISPythonConsole,we will create a classic railroad line symbol by placing a series of short, rotated line markers along a regular line symbol. To do this, we need to perform the following steps:

  1. First, we load our line shapefile:

    lyr = QgsVectorLayer("/Users/joellawhead/qgis_data/shapes/paths.shp", "Route", "ogr")
  2. Next, we get the symbol list and reference the default symbol...