# Calculating real length and slope of roads

I have collected points alongside road in form of csv files with z-values. When imported in QGIS I used Set Z value and Points to path to make line. When I use right button in Identify Features tool I can see that all vertices have appropriate z values. However, when I use \$length function in Field Calculator I get exactly same values as if I have draw line but hand without z values. Also, how can I calculate average slope for same line?

The built-in `\$length` function will only get you the 'horizontal' length along the line, not the true length allowing for the slope. To calculate this:
2. On this new layer, open field calculator and create a new field "h_length" using the function `\$length`. This is the 'horizontal' length of each segment.
3. Also in field calculator, create a field "z_start" using the function `z(start_point(\$geometry))`, and another field "z_end" using the function `z(end_point(\$geometry))`. These denote the elevation at the start and end of each line segment.
4. Calculate the level difference between the start and end point in a new field "z_diff" using the function `"z_start" - "z_end"`.
5. Calculate the 'sloped' length of each line segment in a new field "s_length" based on Pythagoras using the function `sqrt( ("h_length" ^2) + ( "z_diff" ^2))`.
6. If you want to see the gradient of each segment, create a new field "gradient" using the function `"h_length" / "z_diff"` (i.e. a 1 in 40 slope will calculate as 40, swap this round if you require).