I'm importing data, and creating a layer, which has a number of features, each with an f_angle attribute.

I'd like to create a data defined override to rotate the SVG marker by the angle defined by f_angle but am unsure how to do this using pyqgis in QGIS 3.

This question/answer seems to show how to do it is QGIS 2, but QgsDataDefined has been removed in QGIS 3 with the suggestion to use the QgsProperty framework instead. However I'm struggling to find examples/documentation using that.

Can anyone tell me how to create a data defined override to rotate SVG markers based on a feature attribute in QGIS3, using pyqgis?

1 Answer 1


In QGIS 3.x API it looks like:

sl = QgsSvgMarkerSymbolLayer('arrow.svg')
sl.dataDefinedProperties().setProperty(QgsSymbolLayer.PropertyAngle, QgsProperty.fromField('f_angle'))

Or, slightly shorter (But basically the same):

sl = QgsSvgMarkerSymbolLayer('arrow.svg')
sl.setDataDefinedProperty(QgsSymbolLayer.PropertyAngle, QgsProperty.fromField('f_angle'))
  • Perfect. Thank you! Given the time I wasted on this, I can't believe how simple the answer was. Did you follow a documentation trail to get the answer (in which case I'd love to know what/how) or did you already know it?
    – Jonny
    Commented Jan 22, 2019 at 8:19
  • 1
    Well, I have an advantage in that I wrote that part of the API, but the docs at qgis.org/pyqgis/3.4/core/Symbol/… and qgis.org/pyqgis/3.4/core/Property/… . Hopefully they help!
    – ndawson
    Commented Jan 22, 2019 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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