I'm trying to color values along buffered two-point lines with a color ramp in QGIS. The color ramp should represent the height of the lines, that varies linearly from start to end point. Now I cannot figure out how to make that happen. If I choose the bounds of the color ramp to be the minimum and maximum value of the heights of all features, what would need to happen is that the start value on the color ramp is start_height/(max_height-min_height) and the end value on the color ramp is end_height/(max_height-min_height).

Example: say all heights vary between 0km and 40km. Then for a feature that goes from 13km to 1km, the start point no the gradient should be 32% and the end on the gradient should be 2%.

However, I can't specify the start point and end point on the color ramp.

Gradient lines example

A workaround would be to use a two color gradient and have begin and end color data defined, but then I would be stuck with a linear interpolation between two colors, which is not what I want.

1 Answer 1


First set your line to geometry generator points and interpolate points along line

    generate_series(0, length($geometry), 0.000001), 

Then set the filling color of your points (here, based on ramp Viridis)

    0, @geometry_part_count,
    "start"/10, "end"/10 -- my values are between 0 and 10
  • Thanks a bunch, that solves it! This also makes it straightforward to change the point size along the line, creating a 'meteor-like' appearance - I previously used buffer_by_m for this.
    – tammojan
    Commented Feb 18, 2021 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.