2

How could I set LinePlacementFlags with Python in QGIS? My code is something like:

palyr = QgsPalLayerSettings()
palyr.readFromLayer(layer)
palyr.enabled = True
palyr.fieldName = "attribute"

Then I've tried:

palyr.placement= QgsPalLayerSettings.Line

And my labels are on the line. I want them above the line, but I can't figure how to do this. I found there is LinePlacementFlags type. But

palyr.LinePlacementFlags= QgsPalLayerSettings.AboveLine

didn't work.

2

You're looking for placementFlags. So,

palyr.placementFlags = QgsPalLayerSettings.AboveLine

should work. Note that LinePlacementFlags can be combined, so

palyr.placementFlags = QgsPalLayerSettings.AboveLine | QgsPalLayerSettings.BelowLine 

will allow labels above and below the line, but not on over the line.

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.