QGIS – Flexible Label Placement: Select from Range of Values for Distance

expressionlabelingqgisqgis-3

Labeling a line layer in QGIS with many features, not all labels can be drawn without overlapping. Best result in the sense to show as many labels as possible without overlap I got using Parallel mode with allowed positions above and below line, see screenshot:

enter image description here

As you can see, I have set a distance of 12 of the labels from the line. It would now be great to have at least two or three varying distances for the labels, than more labels could be placed. A workaraound would be to use a case when … condition, like:
case when $id %5 = 0 then 20 when $id %4 = 0 then 15 (...) end. However, this is not flexible at all:

enter image description here

Is there an option to allow QGIS to autonomously choose from e.g. two or three fixed distances (like: 5, 10, 15) in a way to automatically optimize label placement?

Best Answer

Playing around a little bit with the settings, there is an astonishingly easy way to achieve that: simply create a random value for the distance: rand(5,20)

enter image description here

Related Question