I do have a line layer containing route segments (input layer). The routes as well as the segments have different lengths. I also have a DEM for the height information.
Now I need to know the minimum and maximum height of each segment to calculate the slope of the segment.
What I've tried so far:
- converted my line layer to point layer using plugin "QChainage", distance set to 10m
- Used the "Drape" tool from processing toolbox to calculate height (z value)
- Added geometry info using "Add geometry attributes" (now I do have my zcoord)
- "Join attributes by nearest" to get the route and segment info on each point ("Join attribute by location" did not work, I don't know why)
maximum("zcoord", 'segment_id')
did not work to get the maximum height value for each segment
What I want to have as a result: I'd like to add an attribute "max"
and "min"
to my input layer.
Does someone have a simple and working solution?
Best Answer
Preparations:
id
field (useExplode line
if that is not the case and create a new field with field calculator and the expression$id
).Workflow:
Run
Menu Processing / Toolbox / Points along geometry
with a distance of 10 m. The resulting points will contain the uniqueid
from your line layer.Create a new attribute called
elevation
with field calculator on the resulting point layer with this expression:raster_value( 'raster_dem', 1,$geometry)
and replaceraster_dem
with the name of your raster (DEM) layer.Create two new attributes
min_elev
andmax_elev
for min and max values, grouped by the uniqueid
, representing the segments the points belong to:minimum( elevation, id)
andmaximum( elevation, id)
.Go to the layer with the line segments and create a new attribute
max
for the maximum elevation for each segment, using this expression (and repeat it replacingmax_elev
withmin_elev
on line 3 to create an attribute for minimum elevation):Remark: end of line 3, the first
'id'
is the name of the unique field in the layerInterpolated
(the layer containing the points created in step 1), the second"id"
is the name of the (corresponding) attribute in the initial line layer. They should normally be the same (as set in the initial line layer).