[QGIS-Developer] setDataDefinedProperty() for color doesnt work for QgsSvgMarkerSymbolLayerV2

M S. msel.mobicom at gmail.com
Thu Dec 13 05:35:12 PST 2018


Hello,
i have a script which works well and changes the pre-defined symbol
QuarterCircle's color and angle :

vLayer = QgsVectorLayer(uri, "myData" , "delimitedtext") #some vector layer

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()


  Then i wanted to change the QgsSimpleMarkerSymbolLayerBase.QuarterCircle
symbol to a 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 doesnt work and all
the colors are black. Can you please help me to find the problem? or  Can
you please give an example portion of code that imports an svg and modify
its color according to some data belongs to a vector layer(data defined
override)?

Qgis Version : 2.18.22
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20181213/5884ffec/attachment-0001.html>


More information about the QGIS-Developer mailing list