Zonal Statistics as Table (Spatial Analyst)

License Level:BasicStandardAdvanced

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

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. If no extension is specified, it will be an INFO table. If the location is in a geodatabase, the output table will be created in that particular type (for example, a file or ArcSDE geodatabase). If the name has a .dbf extension, the output will be in dBASE format.

Table
ignore_nodata
(Optional)

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

  • DATA Within 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.
  • NODATA Within 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.
  • MEAN Calculates the average of all cells in the value raster that belong to the same zone as the output cell.
  • MAJORITY Determines the value that occurs most often of all cells in the value raster that belong to the same zone as the output cell.
  • MAXIMUM Determines the largest value of all cells in the value raster that belong to the same zone as the output cell.
  • MEDIAN Determines the median value of all cells in the value raster that belong to the same zone as the output cell.
  • MINIMUM Determines the smallest value of all cells in the value raster that belong to the same zone as the output cell.
  • MINORITY Determines the value that occurs least often of all cells in the value raster that belong to the same zone as the output cell.
  • RANGE Calculates 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.
  • STD Calculates the standard deviation of all cells in the value raster that belong to the same zone as the output cell.
  • SUM Calculates the total value of all cells in the value raster that belong to the same zone as the output cell.
  • VARIETY Calculates 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 STD 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"


# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")

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

Environments

Related Topics

Licensing Information

ArcGIS for Desktop Basic: Requires Spatial Analyst
ArcGIS for Desktop Standard: Requires Spatial Analyst
ArcGIS for Desktop Advanced: Requires Spatial Analyst
4/10/2014