3

I have a QgsVectorLayer object with field Direction which determines orientation of the symbol of the layer. I use setDataDefinedproperty method to adjust the orientation of the symbol like:

symbol = vLayer.renderer().symbol()
symbol.symbolLayer(0).setDataDefinedProperty(QgsSymbolLayer.PropertyAngle,QgsProperty.fromField("Direction"))

Now I want to add label for Name field with same orientation as symbols. I tried :

label_settings = QgsPalLayerSettings()
label_settings.fieldName = "Name"
label_settings.enabled = True

label_property_collection = QgsPropertyCollection()
label_property_collection.setProperty(QgsPalLayerSettings.TextOrientation,QgsProperty.fromField("Direction"))
label_settings.setDataDefinedProperties(label_property_collection)

labels = QgsVectorLayerSimpleLabeling(label_settings)
vLayer.setLabeling(labels)  

But there is no change for label orientation. How can I achieve that?

1 Answer 1

4

QgsPalLayerSettings enumerator needs to be not TextOrientation but LabelRotation

label_property_collection.setProperty(QgsPalLayerSettings.LabelRotation,QgsProperty.fromField("Direction"))

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.