TransWikia.com

Align calloutlines in the centre of a label for line-objects in QGIS 3.10

Geographic Information Systems Asked by Lordcram on August 23, 2020

I would like to align a calloutline for a label in the centre of the text and with a vertical line to a line object in QGIS 3.10.

At the moment my callout line follows the nearest vertex of the line when I manually move it and is always anchored to the bottom right of the text label (See label on the right in the picture).

It should look like the label on the left in the picture, but the label on the left is based on a point object and not a line object.

enter image description here

Is there a way to achieve this in QGIS 3.10?

One Answer

I don't know what your situation is but the easiest solution is to upgrade to 3.14 where there is now a setting for both Label Anchor Point and Anchor point. QGIS 3.14 callout placement options

If that is not possible you can do it the old geometry generator way. As is very well described here: https://gist.github.com/kgjenkins/1af82a8ffdc3c99bb886e6cd9cdc298f

I have copied the text from that tutorial below in case if ever disappears.

Callouts, sometimes called leader lines, are lines between labels and features on a map. They are useful when constraints of space force a label to be moved away from the feature. The callout helps to reconnect the label to the feature it refers to.

image

There are probably multiple ways to do this, but here is one way using a geometry generator in QGIS 3.x:

callouts_qgis

  1. Turn on labels for the layer Style dock > Labels tab Change "No labels" to "Show labels for this layer" Select the field to "Label with"
  2. Move individual labels The upgrade to QGIS 3.0 has made label placement easier to customize. When you move a label, QGIS tracks the new location using hidden auxiliary storage fields that we'll use to draw the lines.

Make sure the Label Toolbar is enabled (View menu > Toolbars) Select the "Move Label" tool image Click and drag the to move the labels. (The first time you click to move a label, you will be asked for a primary key to use for tracking the labels. Pick a field that has an id or otherwise unique values within your layer.) 3. Add the callout lines In the layer styling dock, click the green + to add a new marker component Set "Symbol layer type" to "Geometry generator" Set "Geometry Type" to "LineString / MultiLineString" Enter the following expression:

make_line(   make_point($x, $y),  
> make_point( "auxiliary_storage_labeling_positionx" ,
> "auxiliary_storage_labeling_positiony" ) )
  1. Improve the label display Add label buffers ("halos") so that the lines won't obscure the text of the label (3rd tab in the style dock) Adjust the label placement (6th tab in the style dock), data defined > alignment set the horizontal alignment to 'Center' set the vertical alignment to 'Half'

Answered by Baswein on August 23, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP