# Calculating area in QGIS, defined as zone with relative elevation compared to a river

I’m trying to do the following in QGIS. When creating a 3D map, I want to follow a line or area of interest, such as a river, and create an area which is measured perpendicular to the line of interest, covering a pre-set relative height differential, say 3 or 5 meters higher.

To break this down into steps:

• I'm trying to draw a line that follows a river. EDIT: removed from this question, I'll post a separate question for this.

• I want to add a calculation that draws an area outlined by 2 lines (one on each side of the river outline created under the step above) calculated at perpendicular angle to the line, plotted where on the DEM / 3D model the elevation is x meters higher. So following the river downstream, the river elevation drops and these lines follow that pattern.

Any idea how this step can be done? edited after question was answered

• Hi quoteunquote, welcome to GIS SE. The policy of this site is to to ask focused questions, see tour. So to improve your chances to get answers, you should ask a separate question for each of your problems. Further: at least problem 1 is not clear to me: what do you want to achieve? Your question is how to get vector data out of OpenStreetMap (OSM)? No need to re-draw features present in OSM, you can download them. Nov 18, 2021 at 8:27
• Hi @Babel, many thanks for your reply. I'll amend my question. What I'm trying to achieve, is to show / calculate the area which is 5 meters above the river I'm tracing, measured in straight lines perpendicular from the river. Nov 18, 2021 at 9:04
• Yes - the final outcome is clear, however not so clear is what you already have and where you're stuck. Adding a screenshot (or even sharing your data) often helps to understand your very problem. Nov 18, 2021 at 9:07
• Which QGIS plugin? QGIS has a lot of plugins. So basically what you want to say is that you don't have a line (vector layer) for your river? If so, this is another question and should be asked separately. Here the basic question seems to be how to get the relevant area from the DEM. Nov 18, 2021 at 11:35
• Thanks, I understand. I have a DEM with elevation data, and I have a map of the same area - this map is Open Street Map, via the QGIS plug-in. On the map is a river. What I don't have is 1) the ability to track the river on the map, and assign the elevation data, from the DEM, to this new linestring. I don't know how to create this. And 2) Once I have this, I am looking to calculate / generate the area that is defined when looking at each point of the river, where is the point perpendicular to this line string where the elevation is 5 meters higher. Nov 18, 2021 at 11:36

This solution provides a workflow to do exactly what you asked for. The workflow might not be the standard way how to calculate flooded areas, but since you asked for it, here is a way how to do it the way you asked for (as you might have reasons to do it this way). The advantage of this procedure, however, is that you can control the single steps and you can retrace in detail the output based on the date you have (see especially last screenshot). So it might have a didactic use as well.

1. The basic idea is to create a grid (polygon) layer and then create an attribute `elevation` for the elevation of each grid-cell, using an expression like `raster_value( 'DEM', 1,centroid(\$geometry))`.

2. Then create a layer called `lines` with perpendicular lines to the river layer: Get the intersection of each grid-cell with the river, thus creating small riverline sections inside of cells. Get the point on this lines closest to the grid's centroid and on this points create lines perpendicular to the river. Use this expression with `Menu Processing / Toolbox / Geometry by expression`:

``````with_variable (
'river',
intersection (
geometry (get_feature_by_id ('river',11)),
\$geometry
),
extend (
make_line (
centroid (@river),
project (
centroid (@river),
100,
90+degrees (
azimuth (
start_point (@river),
end_point (@river)
)
)
)
)
),
100,
0
)
)
``````
1. On the grid layer, check which cells intersect with these perpendicular lines and get the elevetion of the point where these lines intersect the river. As the lines were created based on grid layer cells that intersect the river, they contain the elevation at the river level. So use this expression to create a new attribute `river_elev` on the grid layer: each cell should contain the elevation of the line that intersects this cell. In case of more then one lines crossing the same cell, with `array_min` you get the lowest value, with `array_max` the highest one. Use this expression:

array_min(overlay_intersects('line',elevation))

Now create a new attribute `difference` that returns the difference of the elevation value of each cell and the elevation of the river: `elevation - river_elev`.

You can then select all cells that are within the range of 5 meters of the river elevation with this expression: `difference <= 5`.

Remark: depending on the size of your grid cells and the extent, calculation can take some time. Be sure to save permanently all layers + project before and create a spatial index.

Result: area that fulfills the condition (max. 5 m above river level):

Affected area (detail):

Screenshot: river (blue line), grid cells (orange squares) and auxiliary lines perpendicular to the river (pink). Labels indicate: first line: elevation of the centroid of the cell in question, second line: elevation at river's level of the line crossing the cell (minimum value in case of more then one line). Highlighted in yellow cells where these two values have a difference of less then 5 meters. As you can see, one side of the rived (above) is much steeper, thus less cells are selected: