I have a raster dem from which I've created a slope. Then I'd like to calculate the average and maximum slope on each of some vector lines. I have a vague memory that I have seen a plugin for this but right now I can't seem to find it?

Basically I'm looking for something like the Zonal Statistic Plugin but instead of a polygon, I want to use lines.

  • You will have several options depending on your expected outcome. For instance, (1) whether you want your datapoints along the line at each vertices (nodes) of your input line, or equal interval along the line, or at all intersecting cells of dem where your line overlays; (2) whether the measurement should be slope along the line or dem slope at each point.
    – Kazuhito
    Commented Jul 1, 2017 at 23:10
  • You can also use 'rasterize' method from Processing Tool Box and Raster Calculator.
    – xunilk
    Commented Jul 2, 2017 at 13:12
  • 1
    My idea is slope along the line I think. The reason I ask is that I have downhill ski slopes that need to have average and max slope.
    – oskarlin
    Commented Jul 3, 2017 at 5:43
  • Got that. Then you will probably need high-density sampling interval (enough detail to respect each cell value) on profile tool.
    – Kazuhito
    Commented Jul 3, 2017 at 6:13

3 Answers 3


This is an approach using qProf plugin, which provides slope value at the specified (equal) interval along the line.

enter image description here

Choose Export tab and you will find Topographic profile data option, and then export the data as .csv. Your csv file will have a dirslop column which shows the slope along the line.

Notice it is negative when the slope (between measurement) is upward. Calculate absolute slope first and then average and maximum on your spreadsheet.

  • 1
    Nice! I will try this method. I was hoping for a plugin that did exactly that job. Can't be that hard to create one? I'm thinking about all ski resorts around the world that would benefit from it.
    – oskarlin
    Commented Jul 10, 2017 at 20:52

Another approach uses rasterize method from Processing Tool Box and Raster Calculator. In my example, I used line vector layer and slope raster of next image:

enter image description here

For rasterizing, you first need these raster parameters (see in Metadata Properties) from original raster:

Layer Extent (layer original source projection)
Pixel Size

However, 'Layer Extent' is not in order required for rasterize tool. Must be ordered as: xmin, ymin, xmax, ymax.

In my case, these parameters were:

354971.3488602247089148, 479272.4038835020037368, 4414903.3223166307434440, 4473428.4023900907486677


and they were copy/paste at rasterized tool as in next image (id in line vector layer must be 1):

enter image description here

After run, I got this rasterized line (pseudocolor with 2 classes and transparency for 0 values). This one is perfected aligned with original raster.

enter image description here

Finally, I used next formula in 'Raster calculator expression':

( "Rasterized@1" )  * "utah_demUTM2_slope@1"

to get a new rasterized line; but with slope values instead. Red rectangle at next image point out your required statistic parameters, average and maximum slope, for this vector line.

enter image description here

  • Nice approach! I do prefer not converting the line to raster, but in worst case, this will work.
    – oskarlin
    Commented Jul 10, 2017 at 20:50

I dont know if my solution fit your request but: Given DEM=Lake_100m (raster) and Linea (SHP) calculate the slope on each segment of line

1) Explode Linea--->Segment

2) Field calculator

define two float field in Segment SHP





define field slope in segment SHP and calculate it:

slope= (Z_end_point-Z_start_point)/lenght($geometry)*100


  • Is there a reason why you use make_point to construct a point, instead of simply using start_point($geometry)
    – TimD
    Commented Aug 21, 2019 at 4:20

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.