I need to calculate the mean slope of roads between nodes with QGIS. I have a DEM and a vector (PostGIS) with the roads, nodes are additionally displayed as point shape and also contain an elevation field derived from DEM:

enter image description here

I am looking for the mean slope between those nodes which are connected with a line.

As there are many roads to calculate (see the picture below), I need a workflow which processes all calculations at once.Either output as raster (with slope values on the roads and NoData for others) or shapefiles containing the the slope are useful for my purpose.

How can I do this?

enter image description here

I have a ArcGIS solution in mind (3D Analyst / interpolate shape), but I'd prefer a QGIS / open source solution!

I tried the Profile Tool Plugin, which only processes one line at once. Further, I was thinking of using a slope raster and failed because of the direction of the slope (contour line streets).

I was looking for other approaches, but it didn't work or I didn't understand them, e.g.:

2 Answers 2


Given DEM (raster) and Linea (SHP) calculate the slope on each segment of line

1) Explode Linea--->Segment 2) Field calculator define two float field Z_end_point raster_value('Lake_100m',1,make_point(x(end_point($geometry)),y(end_point($geometry))))

Z_start_point raster_value('Lake_100m',1,make_point(x(start_point($geometry)),y(start_point($geometry))))

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

  • The last expression is incorrect. The right expression should be slope = (Z_end_point-Z_start_point)/lenght($geometry)*100 Commented Apr 23, 2021 at 17:48

You can do it with a python script. Basically, for each line, you iterate the nodes. for each pair of nodes, you sample the elevation from the raster, and then you calculate the slope.

My plugin "Walking time", uses a very similar approach. maybe you can read its code and adapt:


  • yeah I tried your pretty cool plugin! But unfortunately I don't use QGIS enough to understand python.
    – Kevkev770
    Commented Feb 7, 2018 at 12:17
  • 1
    There is a QGis plugin that can do this: Road slope calculator.
    – MLourdes
    Commented Jun 2, 2023 at 13:19

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.