QGIS Script · Python
Water Level Polygon Generator
Set a target elevation and this script finds every DTM pixel at or below that level, converting them into filled GeoJSON polygons. Use it to map reservoir extent at a given water level, estimate flood inundation, plan cut-and-fill earthworks, or define the boundary polygon for the Lake Volume Calculator.
What you get
generate_contour_level_polygon.pyWhat it does
Elevation threshold to polygon
Finds every DTM pixel at or below a target elevation and converts those pixels into filled GeoJSON polygon features. Run it multiple times at different elevations to model fill scenarios.
Multi-polygon support
Multiple disconnected low-lying areas become separate polygon features, sorted largest-first by area — useful when a site has more than one depression or isolated pocket.
Geometry simplification
Polygons are automatically simplified to reduce vertex count and file size while retaining the overall shape — ready to share or load into other tools without cleanup.
Area and attributes
Each polygon feature carries elevation, area_m2, and polygon_id — import into a spreadsheet or use in further QGIS analysis without any manual editing.
Use cases
Reservoir fill extent
Set the target elevation to the proposed bund height and see exactly how far the water surface would extend at capacity.
Flood inundation mapping
Map which areas on a site would be submerged at a given water level — useful for drainage planning and risk assessment.
Cut-and-fill estimation
Outline the polygon at the design level of a proposed pond or road cutting, then use it as the boundary input for the Lake Volume Calculator to quantify how much earth needs to be moved.
Bund and tank capacity
Quickly assess the storage potential of an existing farm tank or proposed bund before committing to construction.
Pairs with: Lake Volume Calculator
This script defines where the water would be. The Lake Volume Calculator tells you how much — it takes the polygon boundary you generate here and computes volume in cubic metres, litres, and acre-feet from the DTM beneath it.
How to use it
- 1
Load your DTM raster into QGIS. Layer name must contain
dtm. - 2
Check (tick) the DTM in the Layers panel.
- 3
Open Plugins → Python Console → Show Editor.
- 4
Paste the script. At the bottom set
elevation(target water level in metres) and optionallysimplify_tolerance. - 5
Click Run.
Requirements
- QGIS 3.28 or newer
- numpy, rasterio — bundled with QGIS
- shapely, pyproj — install via OSGeo4W Shell if needed
- DTM raster — layer name contains "dtm"
Also in the Terrain Analysis Pack
Get all 6 terrain scripts for $35 — save $15 vs buying individually.