Is there a way to get the height and width of labels in the field calculator? Perhaps with the help of the function editor? Units are in meters.
See also: Creating leader lines for moved labels
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
Perhaps a look at http://pyqt.sourceforge.net/Docs/PyQt4/qfontmetrics.html might help. You can obtain pixel dimensions of a string for a given font as follows:
from PyQt4 import QtGui f = QtGui.QFont("times", 24) fm = QtGui.QFontMetrics(f) >>> fm.width("My test text") 149 >>> fm.height() 36
Since this function doesn't seem to take line breaks into account, I suggest not to use auto-linebreaks in your labels and a) sum up the line height's and b) estimate the maximum of the line width's in order to obtain your labels pixel dimensions. If you have drawn a background to your labels you may have to add twice its x/y size to the width/height.
If you put it all together in a custom function, you may directly use it in the field calculator.
Here is a nice example on how creating custom functions work: http://www.qgistutorials.com/de/docs/custom_python_functions.html