I have a project that has two important data layers. One contains raster data, in this case slope, and another layer that contains a bunch of vector lines. I want the color of the line to reflect the data from the slope layer. Is this possible in QGIS and if so how can it be accomplished? I imagine that you have to use a graduated symbology that employs some sort of custom rule.
-
1This is possible, but you need to be more specific in your question. Lines typically cross long sections of a raster layer, so which particular data from the slope layer are you looking to use for a given line? Is it the average slope? Or do you want the lines broken up into short chunks and each chunk coloured?– Tom BrennanCommented Nov 10, 2023 at 2:57
-
@TomBrennan it needs to be as close to the original raster later as possible so probably needs to be broken up into lots of smaller lines– Ethan CrosbyCommented Nov 10, 2023 at 13:45
-
Remember to add any additional information back into the question itself - comments are transient.– Tom BrennanCommented Nov 11, 2023 at 2:17
1 Answer
You can split your original lines into smaller lines using the "Split lines by maximum length" tool from the Processing Toolbox. The default is 10m, but the best length is going to depend on the detail of your data.
You can then use the Field Calculator to add a new field ('slope') to the Split layer using the following formula, which averages the slope at the start and end of the line.
(raster_value('slope2',1,end_point($geometry))+raster_value('slope2',1,start_point($geometry)))/2
Finally, you can style the lines using a Graduated symbology like the following:
The output looks like this, where blue is very gentle slopes, and red is steep slopes.