[Qgis-user] Bounding Box of Labels

Fuenfer-Koenigstein.Benjamin at swm.de Fuenfer-Koenigstein.Benjamin at swm.de
Thu Jun 29 23:53:30 PDT 2017


Hi,

Is there any method or any other possibility to use bounding box of labels in QGIS geometry generator expression builder?

I want to make a layer styling with labels with leader lines from object's label to the object. I have a PostGIS point geometry source for the actual object and another for the label position. They are related by attribute "id". So generally thanks to great QGIS' geometry generator it's easy to generate a leader line by

make_line($geometry, geometry(get_feature('object_layer', 'id', "id ")))

As an extra challenge, I want to generate the leader line from first or last character of the label, depending if first or last character is closer to the object geometry. The label is positioned above right of label geometry. So if the first character of the label is closer, I can use above method to generate leader to lower left corner of the label. But if the end is closer I would need something like 'label bounding box' to generate leader to lower right corner of the label. Currently I use

make_line(project($geomety,length("label_string")*0.5,radians(90)), geometry(get_feature('object_layer', 'id', "id "))

This way, I project the start point of the leader by length of label text (comes from the attribute "label_string"). With the factor 0.5 I get quite OK results for many labels, but sometimes if the label string contains many narrow or wide characters (i,l,j resp. o,p,g) the leader's start point doesn't get the correct position. With 'label bounding box' it would be easy to always get the right position.

Thanks for any help!

Regards
Benjamin

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20170630/b38e47bc/attachment.html>


More information about the Qgis-user mailing list