1

I'm trying to add a symbolLayer with a line-decoration (line-arrow) to a vectorlayer of linestrings. what i am trying at the moment is to create a new layer and set it's QgsLineSymbol with a list of symbollayers.

# Symbology
        simple_props = { 'width' : '1', 'color' : '255,255,255' }
        deco_props = { 'width' : '0.26', 'color' : '0,0,255' }

        simple = QgsSymbolLayerV2Registry.instance().symbolLayerMetadata("SimpleLine").createSymbolLayer(simple_props)
        deco = QgsSymbolLayerV2Registry.instance().symbolLayerMetadata("LineDecoration").createSymbolLayer(deco_props)
        s = QgsLineSymbolV2([simple, deco])

        self.ll.setRendererV2( QgsSingleSymbolRendererV2( s ) ) 

Every time QGIS trys to set the QgsLineSymbolV2 it crashes with a win32-exception. what am i doing wrong, or is there a possibilty to just add a new symbollayer to a existing vectorlayer?

2

So i don't know what was wrong, but i found a workaround. now i just add a second symbollayer to the existing symbol in the layer-renderer.

    sl = QgsSymbolLayerV2Registry.instance().symbolLayerMetadata("LineDecoration").createSymbolLayer({ 'width' : '0.26', 'color' : '0,0,0' })
    symbollist = layer.rendererV2().symbols()
    symbol = symbollist[0]
    symbol.appendSymbolLayer(sl)
0

Over 5 years later I realise, but when I tried the accepted answer (in QGIS 2.18), I got a message:

AttributeError: 'NoneType' object has no attribute 'createSymbolLayer'

To fix this, I needed to use ArrowLine instead of LineDecoration as follows:

sl = QgsSymbolLayerV2Registry.instance().symbolLayerMetadata("ArrowLine").createSymbolLayer({ 'width' : '0.26', 'color' : '0,0,0' })  
symbollist = layer.rendererV2().symbols()  
symbol = symbollist[0]  
symbol.appendSymbolLayer(sl)

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.