8

My road network is broken up into segments. I want to produce a map that shows where the segments start and finish.

I don't really want to create a point layer that shows the location of the ends of each line, but will if I have to. And I know that I could categorise segments and use a colour ramp or random colours, but I was looking for something that would look a little more classy.

I was wondering if there is a way to use a colour ramp - or gradient fill - for lines in QGIS? What I envisage is every line segment starts with one colour and finishes with another colour. This would also serve to indicate line direction - another one of my requirements.

Any ideas? Johanna

1
  • 1
    For the line direction, you could use arrows as line style.
    – AndreJ
    Aug 6, 2015 at 7:48

3 Answers 3

5

In the moment there is no way to colour lines with a gradient style.

First buffer your linestrings. Then you can set a gradient colour for the buffer polygons.

Here is a HowTo: How to visualize measure values along linestrings in QGIS?

Another Idea

requirement: your lines have an disinct ID

  1. Cut your linestrings in very small substrings (that it looks like a gradient).

    "______" linestring with id 1 and 100m

    "----------" every single substring must have a distinct id or serial number. Here 1 to 10 (one substring 10m). When all the linestrings have the same direction it would start with 1 und end up with the maximum count of substring.

    1. Categorize the substrings and use a color ramp: 1 green 10 (n substrings) red

Problem could be the large amount of classes, if you have very long linestrings.

1
  • Thanks @Stefan, the idea of buffering the lines will work for me.
    – Johanna
    Aug 6, 2015 at 22:27
5

If your polylines is dense enough and of single type, you could use this approach:

  1. Set a "Single symbol" as symbolizer
  2. Change symbol layer type of a line to "Geometry generator" with type "LineString/MultiLineString" geometry_generator
  3. Set segments_to_lines($geometry) as expression. This function breaks your line into two-point segments and returns multigeometry
  4. Now you can set symbol for every generated segment. Go to symbology page of generated segments and change color expression to: ramp_color('Spectral', @geometry_part_num / @geometry_part_count). "Spectral" is the name of color ramp, you can find others in drop-down list of colors on graduated symbology page. color expression

As a result you'll get something like this: line with gradient color

Another option is to set a basic color for line and then use lighter/darker functions for every segment.

2

As of QGIS 3.30 (released early 2023) and probably a few versions earlier, the interpolated line style seems to allow gradient lines.

The start and end values don't seem to matter for this use case. I just picked 1 and 100 as nice round numbers.

QGIS settings for interpolated lines that will draw the line with a gradient

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.