Scalable Vector Graphics (SVG) are an XML standard that defines vector graphics that can be scaled at any resolution. QGIS can use SVG files as markers for points. In this recipe, we'll use Python to apply one of the SVG symbols included with QGIS to a point layer.
For this recipe, download the following zipped point shapefile layer from https://geospatialpython.googlecode.com/files/NYC_MUSEUMS_GEO.zip.
Extract it to your qgis_data
directory.
In the following steps, we'll load the vector layer, build a symbol layer and renderer, and add it to the layer, as follows:
src = "/Users/joellawhead/qgis_data/NYC_MUSEUMS_GEO/NYC_MUSEUMS_GEO.shp"
lyr = QgsVectorLayer(src, "Museums", "ogr")
svgStyle = {} svgStyle['fill'] = '#0000ff' svgStyle['name'] = 'landmark/tourism=museum.svg' svgStyle['outline'] = '#000000' svgStyle['outline-width'] = '6.8' svgStyle['size'] = '6'
symLyr1 = QgsSvgMarkerSymbolLayerV2.create(svgStyle)
lyr.rendererV2().symbols()[0].changeSymbolLayer(0, symLyr1)
QgsMapLayerRegistry.instance().addMapLayer(lyr)