Using QGIS to filter routes by minimum elevation
After yesterday's post about finding snowshoe routes using Swiss OpenData and QGIS I had one open question: how to also filter the routes by their minimum elevation?
As winter turns to spring and the snow starts melting this is necessary to find routes that probably still have snow on them.
The data from opendata.swiss has the route geometry, and various pre-existing fields for the route length, maximum ascent, and so on, but there is no direct field that contains the route's minimum elevation, so it cannot be used directly in a filter.
Assuming that this is the sort of thing that must be both possible and straightforward, I asked the QGIS community on the Fediverse. @tlohde@fediscience.org was kind enough to reply, and this post is adapted from their suggestions.
The rest of this post assumes you have already followed the steps in Finding snowshoe routes using Swiss OpenData and QGIS.
Outline
We are going to:
- Create a new column in the snowshoe data to contain the minimum elevation of each route.
- Apply a QGIS function,
z_min, to populate this column. - Update the existing filter to exclude routes with a minimum elevation below 1,500 metres.
Creating and populating the column
- Open the “Field calculator” for the snowshoe attribute table.
- Open the layer menu by right clicking the “schneeschuhwanderwege_2056.gpk” layer in the layer pane (bottom left)
- From the menu click “Open Attribute Table” to open the attribute table pane below the map.
- Open the “Field Calculator by clicking the “Edit” button and then the “Open field calculator” button in the toolbar above the attribute table
- Create a new “min_elev” column in the data.
- Ensure “Create a new field” is checked.
- Enter “min_elev” in the “Output field name” field
- Enter “
z_min($geometry)” in the “Expression” field - Click “OK”
This has created a new column in the snow show data called “min_elev”, with a value calculated as the lowest Z point (elevation) in the route geometry for that row.
You can verify this in the attribute table. Scroll the table to the right and you will see the new min_elev column at the end.
Exclude routes below 1,500 metres
- Click the “Edit” button in the attribute pane to disable editing.
- Open the layer menu by right clicking the “schneeschuhwanderwege_2056.gpk” layer in the layer pane.
- Choose “Filter...” to open the Query Builder.
- Click the “Test” button.
- If you are using the query from yesterday you will see a dialog message, “The where clause returned 39 row(s)”. If you are using a different query the number of rows will be different.
- Click OK to dismiss the dialog.
- Edit the query to add a final clause,
AND min_elev >= 1500. - Click the “Test” button again.
- If you where using the query from yesterday you will see a dialog message, “The where clause returned 9 row(s)”. So 30 routes that dip below 1,500 metres have been removed. If you were using a different query you will see a different number of results.
- Click OK to dismiss the dialog.
- Click OK to dismiss the Query Builder