Calculating Zonal Statistics
This tutorial walks through calculating zonal statistics for raster layers using the Zonal Statistics tool (for polygon zone layers) and the Raster Layer Zonal Statistics tool (for raster zone layers).
Included in this tutorial:
Option 1: the Zonal Statistics Tool (polygon zone layers)
Option 2: the Raster Layer Zonal Statistics tool (raster zone layers)
Software version in examples: QGIS-LTR 3.44.10-Solothurn
Tutorial Data: The tutorial includes demonstration with sample data available here.
Credits: Sally Kaye and L. Meisterlin (2026)
The examples in this tutorial use the Standard Data Package from Tutorial Data. The input rasters were produced by rasterizing two feature classes in the data package: the Tracts_wTable layer based on the int_sm value (named “Tracts_int_sm”) and the BX_FourCDs layer based on the BoroCD value to serve as the zone layer. For more on rasterizing see Converting Vector Features to Rasters.
Option 1: the Zonal Statistics Tool (polygon zone layers)
The Zonal Statistics tool summarizes the values of a raster layer within overlapping polygon vector features that define the “zones.” The result is a vector polygon layer that has the same geometry as the zone polygons with summary attributes from the input raster layer.
Accessing the Tool
Access the Zonal Statistics tool in the Processing Toolbox under the Raster Analysis dropdown (alphabetically last).
Tool Inputs and Parameters
the Zonal Statistics tool options
the Statistics to calculate menu
The Zonal Statistics tool’s options include:
Input layer: Specify the polygon layer that defines the zones within which summaries will be calculated.
Raster layer: Specify the raster layer with cell values to be summarized per zone.
Raster band: Select the band from which to summarize cells, if using a multiband raster layer.
Output column prefix: Add a prefix to field names in the output layer created by the tool.
Statistics to calculate: A checklist allows you to select statistics to calculate within each zone. Click the three dots to view the full list of options and customize statistics (shown in image above). By default, the selected statistics will be count, sum, and mean.
The save location and name of the output file, labeled Zonal Statistics: By default, the tool will produce a temporary layer called Zonal Statistics. To save for future use, click the three dots icon to choose a name and location for the new file.
Click Run to execute the tool.
Example
This example calculates statistics from the Tracts_Int_sum layer based on their spatial overlap with the four polygons of the BX_FourCDs layer. In the Statistics to calculate checklist (shown above), we have selected count, mean, minimum, and maximum.
example input layers, with the unique fields of BX_FourCDs labeling each of its four polygon features
example inputs within the Zonal Statistics tool options
The example results are output as a polygon layer with fields showing chosen statistics for each polygon, shown in the screenshot below.
The layer’s attribute table includes the following fields:
BoroCD: The unique labels for each of the 4 CD polygons.
Shape_Length and Shape_Area: These fields are retained from the fields of the source polygon zone layer, BX_FourCDs.
Summary Statistics calculated based on the input settings:
_count: Total number of cells from input value raster within zone
_mean: Mean value of cells within zone
_min: Minimum value of cells within zone
_max: Maximum value of cells within zone
Note the “_” prefix differentiating new statistics fields from existing fields, which can be changed under Output Column Prefix in the tool’s options.
polygon results of example with corresponding attribute table
Option 2: the Raster Layer Zonal Statistics tool (raster zone layers)
Unlike the Zonal Statistics tool, the Raster Layer Zonal Statistics tool calculates zonal statistics without vector inputs or outputs. Instead, the Raster Layer Zonal Statistics tool summarizes the values of a raster layer based on their overlaps with a raster layer with values that define the “zones.” The output is a table of summary statistic results.
Accessing the Tool
Access the Raster Layer Zonal Statistics tool in the Processing Toolbox under the Raster Analysis dropdown.
Tool Inputs and Parameters
the Raster Layer Zonal Statistics tool options
The Zonal Statistics tool’s options include:
Input layer: Specify the raster layer with cell values to be summarized per zone.
Band number: Select the band from which to summarize cells, if using a multiband raster layer.
Zones layer: Specify the raster layer that defines the zones in which summaries will be calculated.
Zones band number: Select the band from which to define zones, if using a multiband raster layer.
The save location and name of the output file, labeled Statistics: By default, the tool will produce a temporary layer called Statistics. To save for future use, click the three dots icon to choose a name and location for the new file.
Note that unlike the Zonal Statistics tool in Option 1 (using a polygon zone input), the Raster Layer Zonal Statistics tool does not allow you to choose specific statistics to calculate. The tool generates, by default, count, sum, minimum, maximum, and mean for the input cell values by zone.
Click Run to execute the tool.
Example
This example calculates the minimum, maximum, and mean value of the cells in the same input value raster used in Option 1 (Tracts_int_sm) based on their spatial overlap with the rasterized version of the same four polygons of the BX_FourCDs layer (named BX_FourCDs_Raster). The images below illustrate the inputs.
input zone raster layer for this example. (input value raster is the same as shown in the previous example)
example inputs within the Raster Layer Zonal Statistics tool options
The example results are output as a standalone table, shown in the image below.
The table includes the fields listed below. Notice that the calculated statistics values in both Option 1 and Option 2 are identical, because both examples use the same input value raster and calculate the statistics based on the same zones. The only difference is that Option 1’s zone input includes polygon features and the output is a polygon layer, and Option 2’s zone input includes rasterized versions of those polygons and the output is a standalone table.
zone: The raster cell value comprising each zone, equivalent to the CD values of the original polygons.
ft2: Calculated area in sq. feet of each zone (units corresponding with georeferenced units).
Summary Statistics calculated based on the input settings:
sum: Sum of cell values from input value raster within zone
count: Total number of cells from input value raster within zone
mean: Mean value of cells within zone
min: Minimum value of cells within zone
max: Maximum value of cells within zone
resulting output table for the inputs shown above