Raster GIS

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.

Intermediate2 min read

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
FieldTypeDescription
ward_idtextWard code W01 to W84.
ward_nametextWard name.
zonetexturban, peri-urban or rural.
populationintegerResidents.
householdsintegerHouseholds.
area_km2realEllipsoidal area in km².
density_km2realPersons per km².
literacy_raterealLiterate 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

  1. Add DEM 30 m and Wards from the tutorial data.
  1. 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.

    The wards coloured by the mean elevation computed with zonal statistics
    Wards by mean elevation.
  1. The new ward layer has _count (cells inside the ward), _sum, _mean, _min, _max, _std and _median. Style it by _mean with Graduated classes.
  1. Summarise further with Aggregate (group and summarize): group by zone and 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 _count or 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.