3

I have labelled a points layer by defining a line between points and labels, because points were overlapping too much. Using additional columns in the points layer attributes table (LABEL_X and LABEL_Y), I can move the labels manually.

To achieve that, I have added a 'Geometry Generator' in the Style section of the layer's Properties dialog. To define the geometry generator, I have used the following expression where $x and $y are the features' coordinates and LABEL_X and LABEL_Y are the labels' coordinates:

make_line(make_point($x,$y),make_point("LABEL_X","LABEL_Y")).

My issue is that labels do not align properly with the line connecting them to features. There seems to be a default offset. How could I correct it? The images below show (1) the way labels display inside the map canvas and (2) the Geometry Generator definition.


Image 1 : Labels with connecting-to-features lines

enter image description here

Image 2 : Geometry Generator definition

enter image description here

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
wiltomap
  • 2,690
  • 2
  • 22
  • 52
  • how did you define the placement of the label? does it look better if you choose 'offset from point' set to 0? – PieterB Sep 14 '17 at 09:12
  • Placement is Around Point, but the result is the same with Offset from Point. I have tried to change the parameters within this section, without success... – wiltomap Sep 14 '17 at 09:15

1 Answers1

2

I'm not sure of my answer but i think i had something very similar recently. The labelling of your point layer is "data defined", did you check the horizontal and vertical alignment ? both properties have predefined values that should be chosen among ([Left|Center|Right]) or ([Bottom|Base|Half|Cap|Top]).

It seems to me that your labels are currently left-aligned ... no ?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Snaileater
  • 5,743
  • 1
  • 15
  • 26
  • That's it! Many thanks... Instead of adding new columns to my points layer's attributes table, I clicked the both drop-down menus for Horizontal and Vertical alignments and then clicked Edit.... I just had to enter 'Center' for horizontal parameter and 'Half' for the vertical one (as explained in the Description section inside the drop-down menu). Display is now perfect! – wiltomap Sep 14 '17 at 09:35
  • glad it helps ! ... just a question : do u generate the "LABEL_X" and "LABEL_Y" manually ... or ? – Snaileater Sep 14 '17 at 09:41
  • Yes, I just change the position of certain labels manually in the map canvas and these columns update automatically with the new label coordinates. – wiltomap Sep 14 '17 at 11:53