I have a script which works well and changes the symbol QuarterCircle's color and angle :
vLayer = QgsVectorLayer(uri, "myData" , "delimitedtext")
symbol = QgsSymbolV2.defaultSymbol(vLayer.geometryType())
simple_marker = QgsSimpleMarkerSymbolLayerV2()
simple_marker.setShape(QgsSimpleMarkerSymbolLayerBase.QuarterCircle )
simple_marker.setSize(6.0)
ddpAngle=QgsDataDefined( True, True, "Direction")
ddpColor= QgsDataDefined( True, True, "CASE WHEN DATA % 3 = 0 then color_rgb( 255,0,0) WHEN DATA % 3 = 1 then color_rgb( 0,255,0) WHEN DATA % 3 = 2 then color_rgb( 0,0,255) END" )
simple_marker .setDataDefinedProperty( "angle", ddpAngle)
simple_marker .setDataDefinedProperty( "color", ddpColor)
symbol.changeSymbolLayer(0,simple_marker)
vLayer.rendererV2().setSymbol(symbol)
vLayer.triggerRepaint()
I wanted to change the QgsSimpleMarkerSymbolLayerBase.QuarterCircle
symbol to user defined .svg format symbol.
symbol = QgsSymbolV2.defaultSymbol(vLayer.geometryType())
svg_marker = QgsSvgMarkerSymbolLayerV2( 'D:\\sample.svg' )
svg_marker.setSize(12.0)
svg_marker.setOutlineWidth(0.25)
ddpAngle=QgsDataDefined( True, True, "Direction")
ddpColor= QgsDataDefined( True, True, "CASE WHEN DATA % 3 = 0 then color_rgb( 255,0,0) WHEN DATA % 3 = 1 then color_rgb( 0,255,0) WHEN DATA % 3 = 2 then color_rgb( 0,0,255) END" )
svg_marker.setDataDefinedProperty( "angle", ddpAngle)
svg_marker.setDataDefinedProperty( "color", ddpColor)
symbol.changeSymbolLayer(0,svg_marker)
vLayer.rendererV2().setSymbol(symbol)
vLayer.triggerRepaint()
For this one it changes the angle but the color part doesn't work and all the colors are black. Can you please help me find the problem?
UPDATE: I realised that when I do it by manually from desktop app it works(entering data defined override by manually). But when I paste my code to desktop app's python console by changing vLayer
to iface.activeLayer()
it also doesn't change color and it shows no data defined override for color part of it, it just seems deactivated.
Can anyone give an example portion of code that imports an svg and modify its color according to some data belongs to a vector layer?