Sunday 23 October 2016

Straight Lines from Label to Feature in QGIS?


What I’m trying to do is label a series of point features but due to the density of point features I’m going to have to move the labels away from the point features. I then want to use a simple straight line (not an arrow) to show which label refers to which point.


I’ve used the plugin “Easy Custom Labels” to generate the labels and move them to where I want them. But what I’m unable to do is create a simple thin straight line between the point and the table.


The best I’ve achieved is to change the “symbol layer type” (Labels layer > Properties > Style) to “arrow”, uncheck “curved arrows” and uncheck “repeat arrow on each segment”. And then make the head length and thickness 0 and make the “arrow width” and “arrow width at start” as this as possible. But this still creates a chunky line. See image A.


I’ve tried setting the “symbol later type” to “simple line” but this results in lines with kinks/vertices/corners in them. See image B.


Ideally, I’d like straight lines between the labels and the feature (like in image A) that are a similar width to those in image B.


Examples of two types of labeling




Answer



You could use an expression for to create line between label and geometry


enter image description here


Expresion:


CASE 
WHEN (label_x IS NOT NULL AND label_y IS NOT NULL) THEN
make_line(centroid($geometry),make_point(label_x -2,label_y), make_point(label_x ,label_y))
ELSE
NULL
END


And this should the result:


enter image description here


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...