← Back to list

Building a Watershed-Aware Digital Elevation Model (DEM) for Culvert Analysis (Using Open Source…

Why most DEM-based hydrology fails — and how to fix it with watershed conditioning

Prayag Shah · 2025-12-30 16:29 · 18 claps · 3.8 min read
#gis #esri #python #water #hydrology
Open on Medium ↗
Wiki topics: 🔓 · Open Source

Building a Watershed-Aware Digital Elevation Model (DEM) for Culvert Analysis (Using Open Source Data)

Water never respects to poorly prepared elevation models

The Goal

The objective was to produce a Digital Elevation Model (DEM) that:

  1. Respects watershed boundaries
  2. Forces flow through real hydrological crossings
  3. Prevents water from leaking across watershed edges
  4. Produces reliable flow direction outputs

Data Used

All datasets came from publicly available sources from New Brunswick, Canada (GeoNB Data Catalogue), including:

  1. A base DEM (30 m by 30 m)
  2. Watershed boundaries
  3. Streams, wetlands and waterbodies

From Raw DEM to Watershed-Aware Surface

This is the heart of the process. Rather than listing every tool and parameter, I’ll break the workflow into logical phases that explains intent behind each step.

  1. Preparing the Watershed Extents

Watersheds rarely behave nicely at their exact boundaries. Edge effects — such as clipped sloped or truncated channels — can introduce sinks or incorrect flow paths.

To avoid this:

  • Watershed polygons were buffered by 20 m
  • The DEM was clipped using the buffered extents, not the raw boundaries

Key idea:

Hydrology modeling fails quietly when the DEM is clipped too tightly.

Buffered watershed extent to avoid edge effects and flow paths are not artificially truncated at watershed boundaries

Buffered watershed extent to avoid edge effects and flow paths are not artificially truncated at watershed boundaries

Clipping the DEM with buffered extents and only use the area which we are interested in

Clipping the DEM with buffered extents and only use the area which we are interested in

  1. Turning Watershed Boundaries into Raster Constraints

Vector boundaries are visually helpful — but hydrology tools operate on raster.

How to make watershed boundaries meaningful in raster space:

  • Watershed polygons were converted into boundary lines
  • Those lines were then rasterized
  • The raster alignment (cell size, extent, snap raster) was kept identical to the DEM

This alignment step is very critical and even a once cell mismatch can produce incorrect results downstream without any errors.

Key idea:

If your raster don’t line up perfectly, your model may be wrong — even if it runs successfully.

Line representation allowing watershed boundaries to be encoded as raster constraints for hydrological processing

Line representation allowing watershed boundaries to be encoded as raster constraints for hydrological processing

Watershed boundary lines rasterized and aligned to the DEM and maintaining identical cell size, extent and alignment with the measurement of DEM

Watershed boundary lines rasterized and aligned to the DEM and maintaining identical cell size, extent and alignment with the measurement of DEM

3. Encoding Streams, Wetlands, and Waterbodies

Streams, wetlands, and waterbodies define where water should flow — but a raw DEM doesn’t always reflect that and just relying on DEM can go wrong.

To encode hydrology into the model:

  • Each feature type (Streams, wetlands and waterbodies) was converted into raster form
  • All raster were standardized to the same resolution and extent (30 m by 30 m)
  • A consistent value of 20 was assigned so these features could be combined into a single hydrology layer

At the end of this step, streams, wetlands, and waterbodies existed as one unified raster value 20, representing known hydrological pathways.

Key idea:

A DEM alone is not hydrology-aware — features must be explicitly encoded.

Streams, wetlands, and waterbodies encoded into a single raster layer with a value of 20

Streams, wetlands, and waterbodies encoded into a single raster layer with a value of 20

4. Detecting Watershed Crossings Automatically

This step is where the workflow becomes especially powerful.

Watershed boundaries and hydrology features were compared mathematically to identify:

  • Where streams or waterbodies cross watershed boundaries
  • Where they do not

By subtracting the hydrology raster from the watershed boundary raster, it became possible to automatically detect crossing points — exactly where culverts and drainage structures matter most.

The resulting raster clearly distinguished:

  • Boundary-only areas
  • Hydrology-only areas
  • Crossing zones

Key idea:

Crossings should be detected systematically, not manually.

-20 = Watersheds, waterbodies and streams, 0 = Areas where crossings are there and most importantly culverts will be created, 20 = Watershed boundary lines

-20 = Watersheds, waterbodies and streams, 0 = Areas where crossings are there and most importantly culverts will be created, 20 = Watershed boundary lines

5. Conditioning the DEM to Enforce Flow Behavior

Once crossings were identified, the DEM was modified to enforce correct flow behavior.

Specifically:

  • Watershed boundary cells were raised by 20m in elevation which was added to the DEM to raise the height
  • This prevents water from “leaking” across boundaries
  • Flow is naturally forced through valid crossings
  • Boundary_Add is added to the DEM so that boundaries of the waterbody, streams and wetlands is raised by 20 m. Using the Raster calculator = Raster + Boundary_Add

After this conditioning:

  • Sinks and small depressions were filled
  • Flow direction was calculated on the corrected surface

The result was a hydrologically conditioned DEM that respects both natural features and watershed structure.

Key idea:

Small elevation adjustments can dramatically improve flow realism.

Using Raster Calculator which gave Boundary_Add = Con(“Minus_Merged1” == 20, 2, 0) where 2 means only boundaries exist and that raster is used to raise watershed boundaries in the DEM

Using Raster Calculator which gave Boundary_Add = Con(“Minus_Merged1” == 20, 2, 0) where 2 means only boundaries exist and that raster is used to raise watershed boundaries in the DEM

Final Output

The final product is a watershed-aware DEM that:

  • Produces stable and realistic flow direction results
  • Respects hydrological constraints
  • Is suitable for culvert sizing and downstream analysis

More importantly, the workflow is modular, transparent and reproducible using open source data.

Lessons Learned

  • When the flow direction process runs successfully that doesn’t mean that it’s correct 😅
  • Hydrology errors are usually introduced early, not late
  • Raster alignment matters more than tool choice

This workflow isn’t meant to be a perfect or universal solution. It’s a starting point — one that balances accuracy, reproducibility and practicality.

If you wish to discuss over anything specific geoprocessing tools used, or need any help in creating this workflow for yourself or for your organization, feel free to reach out to me☺️.


메타데이터
post_id
63c80c2ed38f
slug
building-a-watershed-aware-digital-elevation-model-dem-for-culvert-analysis-using-open-source-63c80c2ed38f
url
https://medium.com/@prayagshah07/building-a-watershed-aware-digital-elevation-model-dem-for-culvert-analysis-using-open-source-63c80c2ed38f
canonical_url
https://medium.com/@prayagshah07/building-a-watershed-aware-digital-elevation-model-dem-for-culvert-analysis-using-open-source-63c80c2ed38f
author_url
https://medium.com/@prayagshah07
status
ok
fetched_at
2026-06-16 19:09:56