Python pipeline to automatically extract thalweg, bank toe, and bank edge from a
Digital Surface Model (DSM) using centerline-based cross-sections and derivative
(dZ/dX) detection — producing continuous morphological lines for hydraulic model input.
Python · rasterio · geopandasEPSG:2154 · 50 m spacingdZ/dX derivative detectionThalweg · Toe · EdgeDSM · Cross-sections · HEC-RAS input
Defining a river's geometry for hydraulic modelling — the thalweg (deepest point),
bank toes (where the bank meets the floodplain), and bank edges — traditionally requires
manual digitising in GIS, which is slow and subjective. This pipeline automates
the detection of these morphological features from a DSM using a cross-section
approach: perpendicular transects are generated along the river centreline, elevation
profiles are sampled and smoothed, and the first-derivative (dZ/dX) is analysed to
locate break-of-slope points automatically.
The outputs are continuous geometric lines — thalweg, left/right bank toe, left/right
bank edge — ready for export into HEC-RAS geometry or further spatial analysis in QGIS.
Cross-sections are spaced at 50 m with a transect length of
200 m, in EPSG:2154.
Architecture
Four-module pipeline
Module 1
Generate Cross-Sections
Read river centreline (GeoPackage/Shapefile), generate perpendicular transects at 50 m spacing, 200 m length. Export as vector layer.
Module 2
Sample Elevation Profiles
Sample DSM elevation values along each cross-section using rasterio. Output: per-transect elevation profile arrays with distance from centreline.
Module 3
Detect Morphological Features
Smooth each profile, compute dZ/dX derivative, detect thalweg (minimum elevation), left/right bank toe and edge (break-of-slope from derivative peaks).
Module 4
Build Continuous Lines
Connect detected points across all cross-sections into continuous morphological lines (thalweg, toe, edge). Export as GeoPackage for QGIS / HEC-RAS.
Generate cross-sectionstools/02_generate_cross_sections.py — perpendicular transects at 50 m spacing, 200 m length.
03
DSM checktools/03_check_dsm.py — verify DSM extent covers all cross-sections, inspect NoData and resolution.
05
Sample all profilestools/05_sample_all_profiles.py — sample DSM elevation along every transect, save profile arrays.
12
Detect featurestools/12_detect_features_all.py — smooth + dZ/dX + detect thalweg / left-right toe / left-right edge for all cross-sections.
14
Build morpho linestools/14_build_morpho_lines.py — connect detected points into continuous line geometries.
15
Planview QA plottools/15_planview_qa_plot.py — generate plan-view map of all detected lines for visual inspection.
Key QA Figures
Output visualisations
Four QA figures are generated at key stages of the pipeline to validate geometry,
profile sampling, feature detection, and final line outputs.
Figure 1 — Module 1: Cross-sections QA. Perpendicular transects generated
along the river centreline at 50 m spacing, 200 m length, in EPSG:2154. The blue line shows
the centreline; transects are evenly spaced and correctly oriented perpendicular to flow direction.
Figure 2 — Module 3: Profile & Derivative (XS 0050).
Top panel: smoothed DSM elevation profile across the transect.
Bottom panel: dZ/dX first derivative — peaks and troughs mark break-of-slope
locations used to detect toe and edge positions.
Figure 3 — Module 3: Toe & Edge Detection (XS 0050).
Detected morphological features plotted on the elevation profile:
thalweg (minimum), left/right bank toes (inner break-of-slope),
and left/right bank edges (outer break-of-slope).
Figure 4 — Module 4: Planview QA. Final output — continuous morphological
lines (thalweg, left/right bank toe, left/right bank edge) plotted in plan view over the
river corridor. These lines are exported as GeoPackage for direct use in QGIS or HEC-RAS geometry.