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 a symbol of this type.
Getting ready
You can download the point shapefile used in this recipe from https://github.com/GeospatialPython/Learn/raw/master/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:
First, we'll define the path to our point shapefile:
src = "/qgis_data/nyc/NYC_MUSEUMS_GEO.shp"
Then, we'll load the vector layer:
lyr = QgsVectorLayer(src, "Museums", "ogr")
Now, we'll use a Python dictionary to define...