1

I'm making a plugin for QGIS that displays aircrafts in real time. This is how I am setting the symbol styles, but I don't know how to set the angle based on the heading of the airplane. I can do it manually (shown in photo) but I need a way to set this using Python in my plugin. I change the position of each feature as it changes, is there a way I can change a feature rotation? Or is there a way to change the symbol style to set the angle by field attribute?

layer = iface.activeLayer()
symbol = layer.renderer().symbol()

svgStyle = {}
svgStyle['fill'] = '#000000'
svgStyle['name'] = 'C:/OSGeo4W64/apps/qgis/svg/transport/transport_airport.svg'
svgStyle['outline'] = '#000000'
svgStyle['outline-width'] = '0.3'
svgStyle['size'] = '7'

symbol_layer = QgsSvgMarkerSymbolLayer.create(svgStyle)
symbol.changeSymbolLayer(0, symbol_layer)

Manually setting symbol rotation in QGIS

1 Answer 1

2

The property you're looking for is a method from QgsMarkerSymbol it's called dataDefinedAngle(), you can change it by using setDataDefinedAngle(). This method requires a QgsProperty based on a field. You need to create it with the method fromField().

You just need to add this one line at the end of your snippet :

symbol.setDataDefinedAngle(QgsProperty().fromField("Heading"))
1
  • 1
    That worked! Thank you so much! Jun 16, 2021 at 18:09

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.