Whitebox QGIS Practice 27 — Elevation-Area Distribution of Two Basins in 50 m Bands

In practice 26 I pulled elevation statistics for the interval basin (A−B) and basin B. The interval basin sat about 76 m higher on average, and B's median was about 14 m below its mean. Two means cannot tell you how much land lies at which elevation, and that distribution is what matters when you think about flood travel time, snow or vegetation zones. So this time I split the DTM into 50 m elevation bands, counted the band cells inside each basin, and put the two elevation-area distributions side by side.

Two built-in QGIS processing algorithms are enough. Reclassify by table turns elevation into band codes, and Zonal histogram counts the cells of each code inside the polygons. The DTM is 1 m, so one cell is 1 m² and a cell count is an area.

Data

I copied the practice 11 1 m DTM (USGS 3DEP tile 13SDE474426, EPSG:26913, a DTM built from ground points) and the merged polygon layer from practice 26 into a new input folder. The copies have the same hashes as the originals.

InputSourceContent
wb27_input_dtm1m.tifPractice 11 DTM1500×1500 cells, 1 m, float32, NoData −32768 (1,834 cells), elevation 1,712.96 to 2,284.53 m
wb27_input_basins_merged.shpPractice 26 wb26_basins_mergedVALUE 1 = interval basin 1,218,780 m², VALUE 2 = basin B 211,372 m²

Reclassifying elevation into 50 m band codes

The DTM ranges from 1,712.96 m to 2,284.53 m, so I set twelve 50 m bands from 1,700 m to 2,300 m. Instead of serial numbers (1, 2, 3) each band code is its lower bound (1700, 1750, …, 2250). That way the histogram field names later become the elevation itself, such as h_1900, and the table reads without a separate lookup.

I opened Processing Toolbox → Raster analysis → Reclassify by table and entered the following.

FieldValueWhy
Raster layerDTM 1 m elevation (practice 11)Raw elevation
Band numberBand 1
Reclassification table12 rows × 3 columns: min 1700 / max 1750 / value 1700, … , min 2250 / max 2300 / value 225050 m steps, value is the lower bound
Output NoData value−9999NoData suited to an integer output
Range boundariesmin <= value < maxSo a cell at exactly 2,000 m falls in the 2000–2050 band
Use NoData when no range matches valueCheckedValues outside the table do not stay as raw values
Output data typeInt16Codes go up to 2250, so Int16 is enough and the file is small
Reclassified rasterwb27_dtm_bands50m.tif
QGIS Reclassify by table dialog with a Korean interface. Raster layer DTM 1 m elevation (practice 11), band 1 (Gray), a fixed table of 12x3, output NoData -9999, range boundaries min <= value < max, Use NoData when no range matches value checked, and output data type Int16. Behind it, the interval basin in purple and basin B in orange are shaded over the hillshade.
Figure 1. Reclassify by table dialog with the 12-band table, range boundaries and Int16 output.

The default range boundary is "min < value <= max". With the default, a cell at exactly 2,000.0 m lands in the 1950–2000 band. Cells exactly on a boundary are rare in continuous float elevation, but if you are going to call a band "2000–2050 m", including the lower bound matches the name. The run took 0.13 seconds.

Map with the 50 m elevation band raster semi-transparent over the hillshade. The legend runs in 12 steps from 1700-1750 m in blue to 2250-2300 m in red. The northeastern valley is blue and the southwestern ridges are orange and red. A purple line marks the interval basin and a black line marks basin B, with ID 1 = A and ID 2 = B labels near the outlets at the upper right.
Figure 2. The 50 m elevation band raster. The purple line is the interval basin, the black line is basin B.

On the map, basin B sits mostly in the blue and light green bands and only its southern tip reaches orange. The interval basin covers nearly every colour, from blue near the outlet to the red ridges in the southwest. Time to check the numbers.

Counting cells per basin with Zonal histogram

Processing Toolbox → Raster analysis → Zonal histogram adds one field per unique raster value to each polygon, holding the cell count. Where the zonal statistics of practice 26 give summary values such as mean and max, this tool gives a count table per value. It suits categorical rasters such as land cover, or band codes like these.

FieldValueWhy
Raster layerDTM 50 m elevation bands (lower bound)The band codes just made
Band numberBand 1
Vector layer containing zonesBasins merged: 1 = interval A-B, 2 = B (practice 26)Both basins in one layer give one result table
Output column prefixh_h_2250 still fits the 10-character shapefile field limit
Output zoneswb27_basin_band_histogram.shp
QGIS Zonal histogram dialog with a Korean interface. Raster layer DTM 50 m elevation bands (lower bound), band 1 (Gray), zone layer Basins merged: 1 = interval A-B, 2 = B, output column prefix h_, output zones wb27_basin_band_histogram.shp. The layer panel on the left shows the 12-band legend from 1700-1750 m to 2250-2300 m.
Figure 3. Zonal histogram dialog with the band raster and the merged polygons.

It ran in 0.28 seconds. The attribute table has 11 fields from h_1750 to h_2250. The 1700–1750 band has 89,224 cells in the whole DTM but none inside the two basins, so no field was created for it. That fits the basin minimums of 1,764.89 m and 1,765.33 m.

Attribute table of Basins with 50 m band cell counts over the map. The VALUE 1 row reads h_1750 18860, h_1800 82926, h_1850 160537, h_1900 199725, h_1950 162680, h_2000 173759, and the VALUE 2 row reads 7798, 37543, 50105, 44607, 30694, 19319. The remaining fields are off to the right. Map labels read A-B 2000-2050 m: 173,759 m2 and B 2000-2050 m: 19,319 m2.
Figure 4. Zonal histogram attribute table (visible up to h_2000) and labels for the 2000–2050 m band. The remaining values are in the table below.

Area and share per band

I divided each count by the basin's total cell count. When one basin is more than five times larger than the other, shares compare better than absolute areas.

Elevation bandInterval basin A−B area (m²)ShareBasin B area (m²)Share
1750–1800 m18,8601.55%7,7983.69%
1800–1850 m82,9266.80%37,54317.76%
1850–1900 m160,53713.17%50,10523.71%
1900–1950 m199,72516.39%44,60721.10%
1950–2000 m162,68013.35%30,69414.52%
2000–2050 m173,75914.26%19,3199.14%
2050–2100 m153,33412.58%11,7475.56%
2100–2150 m147,37612.09%7,6053.60%
2150–2200 m74,9066.15%1,9130.91%
2200–2250 m33,3092.73%410.02%
2250–2300 m11,3680.93%00%
Total1,218,780100%211,372100%
Bar chart of basin area share per 50 m elevation band. The x axis has 11 bands from 1750-1800 to 2250-2300 and the y axis is the share of basin area in percent. Purple bars for the interval basin A-B peak at 16.4% in 1900-1950 and stay at 12 to 16% across 1850 to 2150. Hatched orange bars for basin B peak at 23.7% in 1850-1900 and fall quickly toward higher bands, close to zero at 2200-2250.
Figure 5. Zonal histogram counts as share of basin area (drawn in matplotlib from the QGIS output table).

The two shapes are clearly different. Basin B is widest in the 1850–1900 m band at 23.71% and thins out quickly above it. The three bands from 1850 to 2000 m hold 59.33% of its area, and only 0.92% lies above 2150 m. Its bulk is in low ground not far from the outlet.

In the interval basin even the widest band (1900–1950 m) holds only 16.39%. Instead, the six bands from 1850 m to 2150 m each hold 12 to 16%, an almost flat run, and 9.81% lies above 2150 m. Its area is spread evenly across the whole elevation range. The "48.7% versus 19.2% above 2,000 m" from practice 26 now shows band by band.

This matters in practice because elevation ties to temperature, precipitation type and snow. Under the same storm, the interval basin with its larger share of high ground may receive snow over a wider area. This data alone cannot give snow cover or runoff timing, though. That needs a local temperature lapse rate or observed snow data. What is confirmed here is the elevation-area distribution.

Independent check

I recomputed the result in a separate script to see whether the reclassification followed the table and the histogram counted correctly. Dividing elevation by 50, flooring and multiplying by 50 in numpy gave the same band codes, with 0 differing cells across all 2.25 million cells. Rasterizing the polygons on the same grid by cell centre and counting per band also matched the attribute table in every band for both basins. The per-basin totals are 1,218,780 and 211,372, exactly the areas from practice 26.

Practical notes

  • The default range boundary in Reclassify by table is "min < value <= max". If you name bands by their lower bound, switch to "min <= value < max".
  • Check that the table covers the full DTM range. If "Use NoData when no range matches value" is off, out-of-range values stay as raw values and mix in like stray codes.
  • Zonal histogram counts only cells whose centre is inside the polygon. With polygons made from the same raster, as here, counts and area match exactly. With boundaries from another source, edge cells make the total differ from the polygon area, so compare the two once.
  • More bands mean more shapefile fields and a very wide attribute table. For a comparison table, export to CSV or convert to a share table as done here.
  • The 50 m step was chosen to give about ten bands over this basin's elevation range of about 520 m. For a basin with a narrower range, use a smaller step to see the shape.

Next

With elevation covered, slope comes next. In practice 26 I noted that a large standard deviation does not mean steep terrain. Next I plan to derive a slope raster from the DTM and compare the slope distributions of the two basins the same way, with band reclassification and Zonal histogram.

Work notes

This session was run by a QGIS startup script that filled in the same dialogs and ran them, and the screens are captures from that run. The original project was left untouched and the work was done in a copy (QGIS_Play_NaGeoAI_20261116_27_elevbands.qgz). The data source is USGS 3DEP (The National Map) tile 13SDE474426, and the original DTM is not redistributed. Figure 5, the shares and the independent check come from a separate script that re-reads the output files. QGIS 3.44.15. First 12 characters of SHA-256:

  • Input DTM 069a9c249240
  • Input merged polygons .shp / .dbf 235891ed214a / 67d3965a6d72
  • 50 m band raster 8ac146e8da50
  • Zonal histogram .shp / .dbf 235891ed214a / bf5a73f6f6d7

This is an English adaptation of a post in the Korean Whitebox QGIS practice series. The original is here.

This post was drafted with the help of AI tools and reviewed by the author. Tool features and data portals change over time, so check the official documentation when you practice.

Comments

Popular posts from this blog

What Is GeoAI, and How Does It Help Disaster Safety?

Getting Started with QGIS: What to Do First

Whitebox QGIS Practice 26 — Elevation Statistics of Two Basins: Means of 2,000.1 m and 1,924.3 m, a 76 m Gap