I would like to add my own SVG symbol instead of a dot. I tried the following.

layer = iface.activeLayer()
svgStyle = {}
svgStyle['fill'] = '#0000ff'
svgStyle['name'] = path
svgStyle['outline'] = '#000000'
svgStyle['outline-width'] = '6.8'
svgStyle['size'] = '6'
symbol = QgsSvgMarkerSymbolLayer.create(svgStyle)

Unfortunately the following error occurs:

TypeError: QgsSingleSymbolRenderer.setSymbol(): argument 1 has unexpected type 'QgsSvgMarkerSymbolLayer'

QgsSingleSymbolRenderer.setSymbol() need a QgsSymbol object not QgsSvgMarkerSymbolLayer.

To set the symbol you can use this, where we are changing the default style (0).

symbol = QgsSvgMarkerSymbolLayer(path)
layer.renderer().symbol().changeSymbolLayer(0, symbol )
  • Thanks for your quick answer. Now there is no more error, but a question mark appears instead of my symbol. I used this path 'landmark/tourism=museum.svg' with a new temporary layer with dots. – daniel95 Jul 22 at 8:24
  • 1
    @daniel95 I updated the answer showing how to show path and properties. Please check. – spatialthoughts Jul 22 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.