How Zonal Statistics works
With the Zonal Statistics tool, a statistic is calculated for each zone defined by a zone dataset, based on values from another dataset (a value raster). A single output value is computed for every zone in the input zone dataset.
The Zonal Statistics as Table tool calculates all, a subset or a single statistic that is valid for the specific input but returns the result as a table instead of an output raster.
A zone is all the cells in a raster that have the same value, whether or not they are contiguous. The input zone layer defines the shape, values, and locations of the zones. An integer field in the zone input is specified to define the zones. A string field can also be used. Both raster and feature datasets can be used as the zone dataset.
The input value raster contains the input values used in calculating the output statistic for each zone.
In the following illustration, the Zone layer demonstrates an input raster that defines the zones. The Value layer contains the input for which a statistic is to be calculated per zone. In this example, the maximum of the value input is to be identified for each zone.
Output data type
The output data type is determined by both the selected statistic type and the value input type. The following table identifies the expected data types of the output raster:
Statistic |
Zone input type |
Value input type |
Output |
---|---|---|---|
Majority |
Integer or String |
Integer * |
Integer |
Maximum |
Integer or String |
Integer, Float |
Same as Value |
Mean |
Integer or String |
Integer, Float |
Float |
Median |
Integer or String |
Integer * |
Integer |
Minimum |
Integer or String |
Integer, Float |
Same as Value |
Minority |
Integer or String |
Integer * |
Integer |
Range |
Integer or String |
Integer, Float |
Same as Value |
STD |
Integer or String |
Integer, Float |
Float |
Sum |
Integer or String |
Integer, Float |
Float |
Variety |
Integer or String |
Integer * |
Integer |
If any cell location on the Zone dataset is NoData, that location will be assigned NoData on the output.
Majority
- The most frequently occurring value in each zone is assigned to all cells in that zone.
- When there is a tie for the majority value in a zone, the output for all cell locations in the zone is assigned the lowest of the tied values.
Example:
Maximum
- The highest value in each zone is assigned to all cells in that zone.
Example:
Mean
- The average of the values in each zone is assigned to all output cells in that zone.
Example:
Median
- The median of the values in each zone is assigned to all output cells in that zone.
- To calculate the median, all the cells in a zone are ranked. If there are n cells in the zone and n is odd, the middle (n/2) value is written to each cell in the zone. If there is an even number of cells, the (n/2) -1 value is output.
Example:
Minimum
- The lowest value in each zone is assigned to all cells in that zone.
Example:
Minority
- The least frequently occurring value in each zone is assigned to all cells in that zone.
- When there is a tie for the minority value in a zone, the output for all cell locations in the zone is assigned the lowest of the tied values.
Example:
Range
- The difference between the maximum and minimum values in each zone is assigned to all cells in that zone.
- The range is defined as:
Zonal Range = Zonal Maximum – Zonal Minimum
Example:
STD
- The standard deviation of the values in each zone is assigned to all cells in that zone.
- The formula for the standard deviation is as follows:Note:
Note that the standard deviation is calculated on the entire population (the "N" method), not estimated based on a sample (the "N-1" method). (For comparison, the calculation for standard deviation is equivalent to the STDEVP, not STDEV, method in Microsoft Excel.)
Example:
Sum
- The sum of all the cell values in each zone is assigned to all cells in that zone.
- The data type of the output raster is floating point. This is because the value for the sum tends to be quite large, and it may not be possible to represent it with an integer value.
Consider, for example, a zone that is 2,500 rows and columns of cells in size, and the value of each cell is 1,000. The sum for that zone would be 2,500 x 2,500 x 1,000 = 6.25 billion. If an integer output is required and the range is within ± 2.147 billion, you can apply the Int tool.
Example:
Variety
- The number of unique values in each zone is assigned to all cells in that zone
Example: