Home / GIS and Open Map Data for Beginners

QGIS Zonal Statistics: Summarize a Raster by Polygon Zones

Aerial view of patchwork agricultural fields and a distant village

Photo: Masood Aslami / Pexels

A raster knows everything about everywhere and nothing about any place in particular. The elevation grid holds a million cells, but the flood plan asks about twelve districts. The rainfall grid is continuous, but the cooperative pays out by farm. Zonal statistics is the bridge: overlay polygon zones on a raster, and for each polygon, summarize the cells inside it into a handful of numbers. Mean elevation per watershed. Maximum flood depth per neighborhood. Total NDVI-weighted biomass per field. The QGIS implementation is a Processing algorithm with a disarmingly simple dialog, and like most simple dialogs it conceals the two decisions that determine whether the output is analysis or numerology: whether the raster and zones truly align, and whether the statistics you chose answer the question you actually have. This guide runs the tool end to end, verifies it on numbers small enough to check by hand, and then teaches the reading of its results.

Interactive tool

Summarize by Zone: The Zonal Statistics Checklist

Check off each step as you finish it. Your progress stays on this page.

0 of 7 complete

0% done

The Tool and Its Inputs

Find it in the Processing Toolbox under Raster analysis, Zonal statistics. The dialog asks for three things. The raster layer: the grid whose values will be summarized, an elevation model, a rainfall surface, an NDVI output from the raster calculator. The vector layer: the polygons that define the zones, farms, districts, watersheds, reserves. And the output column prefix: a short string prepended to every statistic column the tool appends, which matters more than it looks, because a layer that accumulates statistics from three rasters over a season needs prefixes that say which raster and which run each column came from. Then the statistics themselves, chosen from a list: count, sum, mean, minimum, maximum, standard deviation, range, variance, unique values count, and a few specialists. The results are appended as new columns to a copy of your zone layer, one row per polygon, the grid's million opinions distilled into a table a meeting can read. Choose the output as a new file rather than a temporary layer when the numbers matter, for the usual reason: analysis you cannot reopen is analysis you will redo.

A Worked Example Small Enough to Trust

Before trusting the tool on a watershed, trust it on a napkin. Imagine one square zone polygon covering exactly three raster cells, whose values are 2, 4, and 6, a toy elevation strip. Run the tool with the standard statistics and the row for that zone should read: count 3, because three cells fell inside; sum 12, because 2 + 4 + 6 = 12; mean 4, because 12 divided by 3 is 4; minimum 2 and maximum 6; range 4, because 6 - 2 = 4. If your real run's toy test reproduces those numbers, the machinery is aligned and honest, and you can scale up with a clear conscience. This habit, a hand-checkable pilot before the production run, is the cheapest quality control in all of GIS, and zonal statistics rewards it especially, because its failure modes, which the next sections cover, are silent. A tool that misreads your zones will still fill the columns with numbers. They will simply be numbers about somewhere else.

Aerial view of patchwork agricultural fields and a distant village
Aerial view of patchwork agricultural fields and a distant village

Alignment: The CRS and Cell Questions

The algorithm compares polygons against cells, and the comparison is only meaningful when both datasets describe the same earth in compatible terms. The CRS question comes first: raster and vector should share a coordinate reference system, or be reprojected to agree before the run, because on-the-fly display alignment in the canvas does not guarantee the Processing engine sees the same overlay you do. The cell question is subtler: a cell is counted by where its center falls, so zones smaller than a cell, or thin zones threading between cell centers, can return counts of zero or values that plainly belong to the neighboring land. A 30 meter DEM cannot summarize a 10 meter garden plot, no matter how politely you ask. Match the raster's resolution to the zone size with the same honesty you would match a net to the fish. And mind nodata: cells carrying nodata inside a zone are excluded from the statistics, which is correct and consequential, because a zone half-covered by cloud in the source imagery returns a mean of its visible half. The count statistic is your coverage audit: compare each zone's count against the cells its area should contain, and treat zones with suspiciously low counts as estimates, not measurements.

Reading the Output Like an Analyst

The statistics list is a menu of different questions, and choosing among them is the analysis. Mean answers what is typical, and lies politely when the distribution is skewed: mean income per district, mean elevation of a watershed with one great peak. Sum answers how much in total, and is only meaningful when the raster's values are amounts, rainfall depth summed over cells is not total water until cell area enters the arithmetic, a trap that catches someone every season. Maximum and minimum answer what extremes a zone contains, the flood depth that decides evacuations, the lowest pass out of a valley. Standard deviation and range answer how varied the zone is internally, which is sometimes the whole question: a farm whose NDVI varies wildly inside its fences is a different management problem from a uniformly mediocre one. Count is the bookkeeping statistic that audits all the others. Read the results table with the question in the front of your mind and the statistic's definition in the back, and join the enriched layer onward if the numbers must travel: the live join and its baked sibling both accept the output as a table like any other. For the symbology that makes a zonal result legible at a glance, classified colors on the zone layer driven by your new columns, the expression builder and the field tools take it from there.

Where Zonal Statistics Sits in the Workflow

It helps to place the tool in its family. Upstream, the raster calculator manufactures the grids worth summarizing: indices, thresholds, change maps. Sideways, clip raster trims grids to a boundary when the study area, not the summary, is the goal. Downstream, zonal statistics is often the last GIS step before the work leaves for a spreadsheet, a report, or a decision, which is why its honesty checks matter out of proportion to its runtime: nobody re-examines the table once it is in the slide deck. Build the professional habit accordingly. Keep the input raster, the zone layer, and the output in one project folder with names that state their content. Record the statistic definitions you used in the layer's metadata or a plain notes file, because mean-of-visible-cells and mean-of-all-cells diverge exactly when a future reader will assume the other one. And when the zones themselves were drawn by hand for this analysis, remember they are arguments, not facts: a watershed boundary from a DEM and a hand-drawn management zone will produce different truths from the same grid, and the honest report says which zones it used. The tool is simple. The craft is everything around it.

The Zones Are an Argument: Size, Shape, and the Honest Report

The deepest trap in zonal statistics is not in the dialog at all. It is the discovery, well documented in geography, that the same raster summarized through different zone boundaries gives different answers: merge two districts and their means merge weighted by area, split one and a hidden internal contrast steps into the light. Zones are not found in nature the way cell values are; they are drawn, by administrators, by history, by you, and every zonal result is partly a report about the drawing. The professional responses are habits, not settings. Test a second zoning when the conclusion matters: if the story survives aggregation to a different set of boundaries, it is a story about the landscape; if it flips, it was a story about the lines. Match zones to the decision the numbers feed: flood money allocated by district should be summarized by district, however elegant a watershed summary would be, because the decision's geography is the honest geography. Report the zones with the numbers, always: a mean without its zone definition is a rumor with decimals. And keep zone layers versioned like data, because the boundary file from before the redistricting will quietly produce last decade's answers from this year's raster. The tool in the Processing Toolbox takes seconds to run. The judgment around it is the actual analysis, and it is the part your readers are trusting you for when they read the table and believe it.

A Worked Table: Two Districts, One Afternoon

Make the machinery concrete with a miniature. Suppose a summer rainfall raster, values in millimeters per cell, crosses two districts. District North holds four cells inside the raster's coverage: 10, 14, 18, and 22. District South holds three: 30, 30, and 36, with a fourth cell of nodata where a lake sits in the raster. Run Zonal statistics with the default prefix and the table grows two rows of sense. North: count 4, sum 64, mean 16, min 10, max 22, range 12. South: count 3, not 4, because the nodata cell is excluded from every statistic, sum 96, mean 32, min 30, max 36, range 6. Already the toy teaches the professional lessons. The count column exposes the nodata hole that the mean alone would have hidden; a district summarized over less ground than its neighbor is a fact the report should carry. The range separates the districts' characters, North's rainfall varied while South's was uniformly heavy, a distinction invisible if only means were computed, and the reason the statistics list is a menu rather than a single average. And the sum, 96 millimeters-cells, is the number that becomes a volume only after the cell area multiplies it, which the honest analyst does in the field calculator and documents. Scale the toy up to ten thousand cells and forty districts and nothing changes except the stakes: same dialog, same prefix, same discipline of reading count before mean and range before conclusion.

Related Guides

Readers working through this topic usually need its closest companions too. These GIS and open data guides cover the neighboring ground:

Frequently Asked Questions

Where is zonal statistics in QGIS?

In the Processing Toolbox, under Raster analysis, Zonal statistics. Give it a raster layer, a polygon vector layer, an output column prefix, and your chosen statistics, and it appends the results as columns on the zone layer.

Which statistic should I choose?

Match the statistic to the question. Mean for typical values, sum for totals of amount-like data, maximum and minimum for extremes, standard deviation and range for internal variety, and count always, as the audit of how many cells each zone's other statistics rest on.

Why did a zone come back with a count of zero or NULL statistics?

Its polygons likely contain no cell centers, which happens when zones are smaller than the raster's cells or thread between them, or when the raster and vector CRS disagree. Align the CRS and match raster resolution to zone size.

Does nodata inside a zone affect the results?

Yes. Nodata cells are excluded, so a partly clouded or partial-coverage zone returns statistics of its valid cells only. Compare the count statistic against the cells the zone's area should contain to see how much coverage each number rests on.

Is sum the total amount inside the zone?

Only when the raster values are themselves amounts per cell. For rates and depths, like rainfall in millimeters, a true total needs cell area in the arithmetic. Sum alone is the total of cell values, which is not always the physical total people assume.

Photo credits: Masood Aslami (Pexels); Patricia Barrios Jaime (Pexels). Photos are served from this site; follow the credit to the library page for the original.