Visualize a polyline with decreasing opacity towards its ends in QGIS

Using the geometry generator I was able to create the following:

enter image description here

The idea is to overlay transparent parts of the line over each other, with each substring a bit shorter than the one create before.

This is done by several layers of line_substring($geometry,$length-$length*0.1,$length). line_substring creates a part of the handed $geometry based on starting and end points along the line. This exemplary line only goes from 90 % of line length until the end. The next layer could start at 80% of line length, etc.

Depending on your background you might need to do a finer graduation that 10 % of line length in order to create a smooth appearance.


Another possibility is to apply menu processing / toolbox / explode lines and expode the line, i.e. to create a separate line from each line-segment. Now you can color each segment of the original line with a color ramp from transparent to color to transparent, using the id of the exploded lines (i.e. the segment-no. of the original line).

To do that, on the exploded line, change the color to a data driven styly, using the assistant:

enter image description here

In the assistant, set $id (meaning the id of the current feature) as the source, load min/max values (the number of lines/segments). You can change this values manually to adapt the style.

Than apply a color ramp and set the start and end marker to 100% transparency, clicking on the color ramp and changing the markers (you can delete an add markers and change their color):

enter image description here

This gives you the style of the blue line. The yellow line shows the original line with an offset to show the original shape of the line:

enter image description here

If you look close, where the lines/segments touch, they overlap and thus on the transparent parts, you have some darker dots. To remove these, simply change the end cap style from square to flat:

enter image description here

enter image description here