I am using python for QGIS 2.0.1 and I have a vector layer of points representing the positions of state labels. I want to display the 'state abbreviation' attribute on the corresponding point for each feature.
Does anyone have an example using QgsPalLabeling to do this? Any other suggestions are also appreciated.
This is a fairly simple process using the new Labeling tab of the GUI, but I have not found any documentation to make this work programmatically using pyQGIS.
Answer
Just figured this one out thanks to a modification of an older post by dakcarto.
Basically the python would need to look like this (replace everything in bold):
palyr = QgsPalLayerSettings()
palyr.readFromLayer(My Vector Layer)
palyr.enabled = True
palyr.fieldName = 'My Attribute Field Name'
palyr.placement= QgsPalLayerSettings.OverPoint
palyr.setDataDefinedProperty(QgsPalLayerSettings.Size,True,True,'8','')
palyr.writeToLayer(My Vector Layer)
No comments:
Post a Comment