I have a working application of labels to a point array - but the size of the text is not relative to the map scale. This decreases the readability of labels when panning and zooming.
To resolve~
How would one implement a text-size based on MapUnits?
field = str(csvGridFieldNames[index])
csvGrid = ftools_utils.getMapLayerByName(unicode('mfLayer1_Grid'))#str(activeLayer)))
textSize = 7
valLabel = QgsPalLayerSettings()
valLabel.readFromLayer(csvGrid)
valLabel.enabled = True
valLabel.fieldName = field
valLabel.placement= QgsPalLayerSettings.OverPoint
valLabel.setDataDefinedProperty(QgsPalLayerSettings.Size,True,True,'%f' %(textSize),'')
valLabel.writeToLayer(csvGrid)
iface.legendInterface().refreshLayerSymbology(csvGrid)
iface.mapCanvas().refresh()
This question appears related, but having some trouble understanding the doc's...
"...lables 'Data Defined' section in pyqgis"
...and FWIW:
A screen shot of the Qgis tool, with the two (needed) PyQgis settable parameters highlighted in green:
Updates following underdark's advice:
Input syntax errors (on my part) are not raising error flags - but are also not implementing MapUnit based font/label size...
valLabel.SizeUnit = QgsPalLayerSettings.MapUnits
valLabel.setDataDefinedProperty(QgsPalLayerSettings.FontSizeUnit,True,True,':%f' %(textSize),'')
LAST UPDATE [SOLVED] This forums pool of wisdom is awesome. Final thanks to underdark for setting things off right in short. Cheers, (final working code below):
textSize = (abs(scale[0]-scale[1]))/4
valLabel = QgsPalLayerSettings()
valLabel.readFromLayer(csvGrid)
valLabel.enabled = True
valLabel.fontSizeInMapUnits = True
valLabel.fieldName = field
valLabel.placement = QgsPalLayerSettings.OverPoint
valLabel.setDataDefinedProperty(QgsPalLayerSettings.Size,True,True,'%f' %(textSize),'')
valLabel.writeToLayer(csvGrid)
iface.legendInterface().refreshLayerSymbology(csvGrid)
iface.mapCanvas().refresh()