Zonal statistics: summarising raster values by polygon
Calculate the count, mean, minimum, maximum, standard deviation and median of raster cells inside each polygon, such as the elevation of every ward.
You will learn
- Run zonal statistics.
- Read the added statistics fields.
- Combine zonal results with attribute summaries.
Prerequisites
Data for this tutorial
DEM 30 m (synthetic) Download dem.tif
- Format
- GeoTIFF, 1 band, Float32
- Geometry
- Raster, 560 × 480 cells of 30 m
- CRS
- EPSG:32643 (WGS 84 / UTM zone 43N)
- Content
- Elevations 450.01 to 678.95 m; NoData -9999 in the south-west corner
- In Orbis
- Browser panel ▸ Tutorial sample data (synthetic) ▸ DEM 30 m, or Load complete tutorial pack.
Wards (synthetic) Download wards.geojson
- Format
- GeoJSON
- Geometry
- Polygon
- CRS
- EPSG:32643 (WGS 84 / UTM zone 43N)
- Content
- 84 wards (31 peri-urban, 19 rural, 34 urban), 333,497 residents
- In Orbis
- Browser panel ▸ Tutorial sample data (synthetic) ▸ Wards, or Load complete tutorial pack.
Fields used in the tutorials
| Field | Type | Description |
|---|---|---|
ward_id | text | Ward code W01 to W84. |
ward_name | text | Ward name. |
zone | text | urban, peri-urban or rural. |
population | integer | Residents. |
households | integer | Households. |
area_km2 | real | Ellipsoidal area in km². |
density_km2 | real | Persons per km². |
literacy_rate | real | Literate share, per cent. |
Licence: CC0 1.0. All tutorial data is synthetic and generated by Orbis. About the datasets
The task
For each ward you want the mean, lowest and highest elevation.
Steps
- Add DEM 30 m and Wards from the tutorial data.
In the Toolbox, open Zonal statistics. Choose Wards (synthetic) as Zone polygons, DEM 30 m (synthetic) as Value raster, Band 1, and keep Output field prefix
_. Click Run.
Wards by mean elevation.
- The new ward layer has
_count(cells inside the ward),_sum,_mean,_min,_max,_stdand_median. Style it by_meanwith Graduated classes.
- Summarise further with Aggregate (group and summarize): group by
zoneand add Average of_mean.
Expected result
Every ward has elevation statistics. Ward W01, for example, contains 1,459 cells with a mean elevation of about 491.3 m (485.6 to 502.8 m).
Common mistakes
- Small polygons. A polygon smaller than a cell may contain no cell centre; its count is 0 and its statistics are empty.
- Averaging means. The mean of the ward means is not the mean of all cells, because wards have different sizes. Weight by
_countor use_sum/_count.
Troubleshooting
- All statistics are empty. The polygons do not overlap the raster, or the raster is opened for display only (load its pixels first).
- Points instead of polygons. For values at points, use Sample raster values at points.