Skip To Content

Zonal Statistics as Table

Available with Spatial Analyst license.

Summary

Summarizes the values of a raster within the zones of another dataset and reports the results to a table.

Learn more about how Zonal Statistics works

Illustration

Zonal Statistics as Table illustration
ZonalStatisticsAsTable(ZoneRas, "Value", ValRas, OutTable, "ALL")

Usage

  • A zone is defined as all areas in the input that have the same value. The areas do not have to be contiguous. Both raster and feature can be used for the zone input.

  • When the Cell size of the Input raster or feature zone data (in_zone_data in Python) and the Input value raster (in_value_raster in Python) is different, the output cell size will be the Maximum Of Inputs, and the Input value raster will be used as the Snap Raster internally. If the cell size is same, but the cells are not aligned, the Input value raster will be used as the snap raster internally. Either of these cases will trigger an internal resampling before the zonal operation is performed.

    When the zone and value inputs are both rasters of the same cell size and the cells are aligned, they will be used directly in the tool, and will not be resampled internally during the tool execution.

  • If the Input raster or feature zone data (in_zone_data in Python) is a raster, it must be an integer raster.

  • If the Input raster or feature zone data (in_zone_data in Python) is a feature, it will be converted to a raster internally, using the cell size and cell alignment from the Input value raster (in_value_raster in Python).

  • If the Input raster or feature zone data (in_zone_data in Python) is a point feature, it is possible to have more than one point contained within any particular cell of the value input raster. For such cells, the zone value is determined by the point with the lowest ObjectID field (for example, OID or FID).

  • If the Input raster or feature zone data (in_zone_data in Python) has overlapping polygons, the zonal analysis will not be performed for each individual polygon. Since the feature input is converted to a raster, each location can only have one value.

    An alternative method is to process the zonal operation iteratively for each of the polygon zones and collate the results.

  • When specifying the Input raster or feature zone data (in_zone_data in Python), the default zone field will be the first available integer or text field. If no other valid fields exist, the ObjectID field (for example, OID or FID) will be the default.

  • The Input value raster (in_value_raster in Python) can be either integer or floating point. However, when it is floating-point type, the options for calculating majority, median, minority, and variety will not be available.

  • For majority and minority calculations, when there is a tie, the output for the zone is based on the lowest of the tied values. See how Zonal Statistics works for more information.

  • A field or series of fields will be created in the output table, depending on the setting of the Statistics type. When the Value input is integer, all of the statistics (Minimum, Maximum, Range, Mean, Standard deviation, Sum, Variety, Majority, Minority, and Median) are available to be calculated. If the Value input is floating point, the Majority, Minority, Median, and Variety statistics will not be calculated.

  • The data type for each value under the items in the output table is dependent on the zonal calculation being performed. See how Zonal Statistics works for the specific behavior of any statistic.

  • The number of rows in the output table is the number of zones.

  • By default, this tool will take advantage of multi-core processors. The maximum number of cores that can be utilized is limited to four.

    If you want the tool to use fewer cores, use the parallelProcessingFactor environment setting.

  • See Analysis environments and Spatial Analyst for additional details on the geoprocessing environments that apply to this tool.

Syntax

ZonalStatisticsAsTable (in_zone_data, zone_field, in_value_raster, out_table, {ignore_nodata}, {statistics_type})
ParameterExplanationData Type
in_zone_data

Dataset that defines the zones.

The zones can be defined by an integer raster or a feature layer.

Raster Layer; Feature Layer
zone_field

Field that holds the values that define each zone.

It can be an integer or a string field of the zone dataset.

Field
in_value_raster

Raster that contains the values on which to calculate a statistic.

Raster Layer
out_table

Output table that will contain the summary of the values in each zone.

The format of the table is determined by the output location and path. By default, the output will be a geodatabase table. If the path is not in a geodatabase, the format is determined by the extension. If the extension is .dbf, it will be in dBASE format. If no extension is specified, the output will be an INFO table.

Table
ignore_nodata
(Optional)

Denotes whether NoData values in the Value input will influence the results of the zone that they fall within.

  • DATAWithin any particular zone, only cells that have a value in the input Value raster will be used in determining the output value for that zone. NoData cells in the Value raster will be ignored in the statistic calculation. This is the default.
  • NODATAWithin any particular zone, if any NoData cells exist in the Value raster, it is deemed that there is insufficient information to perform statistical calculations for all the cells in that zone; therefore, the entire zone will receive the NoData value on the output raster.
Boolean
statistics_type
(Optional)

Statistic type to be calculated.

  • ALLAll of the statistics will be calculated. This is the default.
  • MEANCalculates the average of all cells in the value raster that belong to the same zone as the output cell.
  • MAJORITYDetermines the value that occurs most often of all cells in the value raster that belong to the same zone as the output cell.
  • MAXIMUMDetermines the largest value of all cells in the value raster that belong to the same zone as the output cell.
  • MEDIANDetermines the median value of all cells in the value raster that belong to the same zone as the output cell.
  • MINIMUMDetermines the smallest value of all cells in the value raster that belong to the same zone as the output cell.
  • MINORITYDetermines the value that occurs least often of all cells in the value raster that belong to the same zone as the output cell.
  • RANGECalculates the difference between the largest and smallest value of all cells in the value raster that belong to the same zone as the output cell.
  • STDCalculates the standard deviation of all cells in the value raster that belong to the same zone as the output cell.
  • SUMCalculates the total value of all cells in the value raster that belong to the same zone as the output cell.
  • VARIETYCalculates the number of unique values for all cells in the value raster that belong to the same zone as the output cell.
  • MIN_MAXBoth the minimum and maximum statistics are calculated.
  • MEAN_STDBoth the mean and standard deviation statistics are calculated.
  • MIN_MAX_MEANThe minimum, maximum and mean statistics are calculated.
String

Code sample

ZonalStatisticsAsTable example 1 (Python window)

This example summarizes the values of a raster within the zones defined by a polygon shapefile and records the results in a table.

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outZSaT = ZonalStatisticsAsTable("zones.shp", "Classes", "valueforzone",
                                  "zonalstattblout", "NODATA", "SUM")
ZonalStatisticsAsTable example 2 (stand-alone script)

This example summarizes the values of a raster within the zones defined by a polygon shapefile and records the results in a .dbf file.

# Name: ZonalStatisticsAsTable_Ex_02.py
# Description: Summarizes values of a raster within the zones of 
#              another dataset and reports the results to a table.
# Requirements: Spatial Analyst Extension

# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *

# Set environment settings
env.workspace = "C:/sapyexamples/data"

# Set local variables
inZoneData = "zones.shp"
zoneField = "Classes"
inValueRaster = "valueforzone"
outTable = "zonalstattblout02.dbf"


# Execute ZonalStatisticsAsTable
outZSaT = ZonalStatisticsAsTable(inZoneData, zoneField, inValueRaster, 
                                 outTable, "NODATA", "MEAN")

Licensing information

  • ArcGIS Desktop Basic: Requires Spatial Analyst
  • ArcGIS Desktop Standard: Requires Spatial Analyst
  • ArcGIS Desktop Advanced: Requires Spatial Analyst

Related topics