QGIS Symbology – Variable for Symbol Width in Expressions

expressionoffsetqgissymbologywidth

Using QGIS 3.22.1. I have straight lines connecting two points. These lines are stored in two separate layers, one layer for each direction.

I am using a graduated size renderer to display these lines. Now they do of course overlap. To prevent that from happening I want to set an offset having the size of the line's width. I know there is a variable to get the current features color (@symbol_color). Is there a similar variable (or some way) to get the current features width? I want to use it in data defined offset:

enter image description here

Best Answer

When you set the line size with data driven override, you can use the same expression, divided by 2 (offset just half of the line width to keep in touch with the other line) for the offset.

You can use e.g. the assistant to automatically generate stroke width with scale method linear or exponential. When set, you can look up and copy the expression generated based on these settings (see below) under the icon Data defined override > Edit.... Copy the expression and paste it under Offset > Data defined override - don't forget to divide it by 2:

![enter image description here

enter image description here

When using the assistant for data defined override for stroke width with input source the attribute named width with min/max values from 0.1 to 0.7 that should be styled with stroke width from 1 to 10 with exponential scale methdod and exponent 0.57, the expression generated looks like this:

coalesce(scale_exp("width", 0.1, 0.7, 1, 10, 0.57), 0)
Related Question