Show Navigation | Hide Navigation
You are here:
Extensions > Spatial Analyst > Spatial Analyst functional reference > Zonal (Spatial Analyst)

Zonal Statistics

Release 9.3
Last modified September 7, 2011
E-mail This Topic Printable Version Give Us Feedback

Print all topics in : "Zonal (Spatial Analyst)"


Related Topics

Calculates statistics on values of a raster within the zones of another dataset.

Learn more about how Zonal Statistics works


Usage tips

Command line syntax
An overview of the Command Line window
ZonalStatistics_sa <in_zone_data> <zone_field> <in_value_raster> <out_raster> {MEAN | MAJORITY | MAXIMUM | MEDIAN | MINIMUM | MINORITY | RANGE | STD | SUM | VARIETY} {DATA | NODATA}

Parameter Explanation Data Type
<in_zone_data>

Dataset that defines the zones.

It can be a raster or feature dataset.

Composite Geodataset
<zone_field>

Field that holds the values that define each zone.

Field
<in_value_raster>

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

Composite Geodataset
<out_raster>

The raster to be created.

Raster Dataset
{MEAN | MAJORITY | MAXIMUM | MEDIAN | MINIMUM | MINORITY | RANGE | STD | SUM | VARIETY}

Statistic type to be calculated.

  • MEAN  — Calculates the average of all cells in the input in_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 input in_value_raster that belong to the same zone as the output cell.
  • MAXIMUM  — Determines the largest value of all cells in the input in_value_raster that belong to the same zone as the output cell.
  • MEDIAN  — Determines the median value of all cells in the input in_value_raster that belong to the same zone as the output cell.
  • MINIMUM  — Determines the smallest value of all cells in the input in_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 input in_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 input in_value_raster that belong to the same zone as the output cell.
  • STD  — Calculates the standard deviation of all cells in the input in_value_raster that belong to the same zone as the output cell.
  • SUM  — Calculates the total value of all cells in the input in_value_raster that belong to the same zone as the output cell.
  • VARIETY  — Calculates the number of unique values for all cells in the input in_value_raster that belong to the same zone as the output cell.

String
{DATA | NODATA}

Denotes whether NoData values on 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
Data types for geoprocessing tool parameters


Command line example

ZonalStatistics_sa c:/data/ras_1 Value c:/data/ras_2 c:/data/final_1 MEAN DATA

Scripting syntax
About getting started with writing geoprocessing scripts
ZonalStatistics_sa (in_zone_data, zone_field, in_value_raster, out_raster, statistics_type, ignore_nodata)

Parameter Explanation Data Type
in_zone_data (Required)

Dataset that defines the zones.

It can be a raster or feature dataset.

Composite Geodataset
zone_field (Required)

Field that holds the values that define each zone.

Field
in_value_raster (Required)

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

Composite Geodataset
out_raster (Required)

The raster to be created.

Raster Dataset
statistics_type (Optional)

Statistic type to be calculated.

  • MEAN  — Calculates the average of all cells in the input in_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 input in_value_raster that belong to the same zone as the output cell.
  • MAXIMUM  — Determines the largest value of all cells in the input in_value_raster that belong to the same zone as the output cell.
  • MEDIAN  — Determines the median value of all cells in the input in_value_raster that belong to the same zone as the output cell.
  • MINIMUM  — Determines the smallest value of all cells in the input in_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 input in_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 input in_value_raster that belong to the same zone as the output cell.
  • STD  — Calculates the standard deviation of all cells in the input in_value_raster that belong to the same zone as the output cell.
  • SUM  — Calculates the total value of all cells in the input in_value_raster that belong to the same zone as the output cell.
  • VARIETY  — Calculates the number of unique values for all cells in the input in_value_raster that belong to the same zone as the output cell.

String
ignore_nodata (Optional)

Denotes whether NoData values on 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

Data types for geoprocessing tool parameters


Script example

# ZonalStatistics.py
# Description: Calculates statistics on values of a raster 
#   within the zones of another dataset.
# Requirements: None
# Author: ESRI
# Date: Sept 6, 2005
# Import system modules
import arcgisscripting

# Create the Geoprocessor object
gp = arcgisscripting.create()

try:
    # Set the input files
    inRaster1 = "c:/data/ras_1"
    inRaster2 = "c:/data/ras_2"

    # Set the output raster name
    outRaster = "c:/data/final_1"

    # Check out Spatial Analyst extension license
    gp.CheckOutExtension("Spatial")

    # Process: Zonal Statistics
    cellSize = 1
    statisticType = "MEAN"

    gp.ZonalStatistics_sa(inRaster1, "Value", inRaster2, outRaster, statisticType, "DATA")

except:
    # If an error occurred while running a tool, then print the messages
    print gp.GetMessages()

Map Algebra syntax
See ZonalMajority , ZonalMax, ZonalMean, ZonalMedian, ZonalMin, ZonalMinority, ZonalRange, ZonalStd, ZonalSum, or ZonalVariety, depending on the desired zonal statistic. For a summary of zonal statistics, see ZonalStats.

ArcObjects syntax
IZonalOp::ZonalStatistics (zone As IGeoDataset, value As IGeoDataset, type As esriGeoAnalysisStatisticsEnum, ignoreNoData As Boolean) As IGeoDataset

Parameter Explanation
zone An input Raster, RasterDataset, RasterBand, RasterDescriptor, FeatureClass, or FeatureClassDescriptor that identifies the zone for each value cell location.
value An input integer or floating-point Raster, RasterDataset, RasterBand, or RasterDescriptor defining the values of the cells to be used in the zonal calculations.
type An esriGeoAnalysisStatisticsEnum defining the zonal statistic to calculate within each zone.
The enumeration types are:
  • esriGeoAnalysisStatsMajority  — Majority value
  • esriGeoAnalysisStatsMaximum  — Maximum value
  • esriGeoAnalysisStatsMean  — Mean value
  • esriGeoAnalysisStatsMedian  — Median value
  • esriGeoAnalysisStatsMinimum  — Minimum value
  • esriGeoAnalysisStatsMinority  — Minority value
  • esriGeoAnalysisStatsRange  — Range of values
  • esriGeoAnalysisStatsStd  — Standard deviation of values
  • esriGeoAnalysisStatsSum  — Sum of the values
  • esriGeoAnalysisStatsVariety  — Variety of the values
ignoreNoData A Boolean defining the manner in which NoData values on the valueDataset that fall within a zone defined by the zoneDataset will influence the output results.
If True, and if a NoData value exists in a cell on the value raster within any particular zone defined by zoneDataset, the cell will be ignored, and only cells on the value raster that have data values within the zone will be used in the processing for the output.
If False, and if a NoData value exists on the value raster within any particular zone defined by zoneDataset, there is insufficient information to complete the computation of the values for all the cells within the zone, and the entire zone will receive the NoData value on the output raster and will not appear in the output table.

ArcObjects example

' Create the RasterZonalOp object
Dim pZonalOp As IZonalOp
Set pZonalOp = New RasterZonalOp

' Declare the input zone raster object
Dim pZoneRaster As IGeoDataset

' Calls function to open a raster dataset from disk
Set pZoneRaster = OpenRasterDataset ("D:\SpatialData", "zoneraster")

' Declare the input value raster object
Dim pValueRaster As IGeoDataset

' Calls function to open a raster dataset from disk
Set pValueRaster = OpenRasterDataset("D:\SpatialData", "valueraster")	

' Declare the output raster object
Dim pOutputRaster As IGeoDataset

' Calls the method
Set pOutputRaster = pZonalOp.ZonalStatistics (pZoneRaster, pValueRaster, _
                     esriGeoAnalysisZonalStatsMean, True)

Please visit the Feedback page to comment or give suggestions on ArcGIS Desktop Help.
Copyright © Environmental Systems Research Institute, Inc.