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
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using icons as vector layer symbols


In addition to the default symbol types available in QGIS, you can also use TrueType fonts as map symbols. TrueType fonts are scalable vector graphics that can be used as point markers. In this recipe, we'll create this type of symbol.

Getting ready

You can download the point shapefile used in this recipe from https://geospatialpython.googlecode.com/files/NYC_MUSEUMS_GEO.zip.

Extract it to your qgis_data directory in a folder named nyc.

How to do it…

We will load a point shapefile as a layer and then use the character G in a freely-available font called Webdings, which is probably already on your system, to render a building icon on each point in the layer. To do this, we need to perform the following steps:

  1. First, we'll define the path to our point shapefile:

    src = "/qgis_data/nyc/NYC_MUSEUMS_GEO.shp"
    
  2. Then, we'll load the vector layer:

    lyr = QgsVectorLayer(src, "Museums", "ogr")
    
  3. Now, we'll use a Python dictionary to define the font properties:

    fontStyle = {}
    fontStyle...