ArcGIS for Desktop

  • Documentation
  • Pricing
  • Support

  • My Profile
  • Help
  • Sign Out
ArcGIS for Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS for Desktop

A complete professional GIS

ArcGIS for Server

GIS in your enterprise

ArcGIS for Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Pricing
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

Help

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • More...

Zonal Statistics

Available with Spatial Analyst license.

  • Summary
  • Illustration
  • Usage
  • Syntax
  • Code Sample
  • Environments
  • Licensing Information

Summary

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

Learn more about how Zonal Statistics works

Illustration

Zonal Statistics illustration
OutRas = ZonalStatistics(ZoneRas, "VALUE", ValRas, "MINIMUM")

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 datasets can be used for the zone input.

  • When the zone and value inputs are both rasters of the same resolution, they will be used directly.

    If the resolutions are different, an internal resampling is applied to make them match before the zonal operation is performed.

    Should there be any NoData cells in the inputs, the resampling may cause there to be larger areas of NoData in your output than you might have expected. To avoid this situation, either Resample the coarser input rasters to the resolution of the finer input raster, or set the Cell size to Minimum Of Inputs in the Raster Analysis environment.

  • If the zone input is a raster dataset, it must have an attribute table. The attribute table is usually created automatically for integer rasters, but may not be under certain circumstances. You can use Build Raster Attribute Table to create one.

  • If the zone input is a feature dataset, a vector-to-raster conversion will be internally applied to it. To ensure that the results of the conversion will align properly with the value raster, it is recommended that you check to ensure the extent and snap raster are set appropriately in the environment settings and the raster settings.

    Since the internal raster must have an attribute table, an error will occur if one was not created in the conversion. If this happens, convert your feature dataset directly with Feature To Raster, Polygon To Raster, Point To Raster, or Polyline To Raster. Generate an attribute table for it as described in the previous tip and use the resulting raster as your Zone input.

  • If the zone input is a feature dataset with relatively small features, keep in mind that the resolution of the information needs to be appropriate relative to the resolution of the value raster. If the areas of single features are similar to or smaller than the area of single cells in the value raster, in the feature-to-raster conversion some of these zones may not be represented.

    To demonstrate this, try converting the feature dataset to a raster with the appropriate feature-to-raster conversion tool and specify the resolution to be that of the Value raster. The result from this conversion will give an indication about what the default output of the zonal operation will be.

    If you have fewer results in the output than you expected, you need to determine an appropriate raster resolution that will represent the detail of your feature input, and use this resolution as the Cell Size of the Raster Analysis Settings of the Environment.

  • If the zone input is a point feature dataset, 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 highest feature ID.

  • If the zone feature input 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 statistics iteratively for each of the polygon zones and collate the results.

  • It is recommended to only use rasters as the zone input, as it offers you greater control over the vector-to-raster conversion. This will help ensure you consistently get the expected results.

  • When specifying the input zone data, the default zone field will be the first available valid field. If no other valid fields exist, the ObjectID field (for example, OID or FID) will be the default.

  • If a reserved field (for example, OBJECTID, FID, or OID) is selected for the Zone field, then this may cause some ambiguity in the result. The result includes the particular reserved field name necessary for the particular output format type, as well as the Zone field specified. If the specified field has the same name as the reserved field for the particular output format, in the output, the name for the zone field will be altered in such a way that all field names in the result are unique.

    Note:

    To make a field of unique values that does not have a reserved name, use the Add Field and Calculate Field geoprocessing tools.

  • The input value raster can be either integer or floating point. However, when it is floating-point type, the zonal calculations for majority, median, minority, and variety will not be computed.

  • For majority and minority calculations, when there is a tie, the output for the zone is based on the lowest of the tied values.

  • The data type of the output is dependent on the zonal calculation being performed and the input value raster type. See how Zonal Statistics works for more information.

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

    If you wish 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

ZonalStatistics (in_zone_data, zone_field, in_value_raster, {statistics_type}, {ignore_nodata})
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
statistics_type
(Optional)

Statistic type to be calculated.

  • 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.
String
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. This is the default.
  • 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

Return Value

NameExplanationData Type
out_raster

The output zonal statistics raster.

Raster

Code Sample

ZonalStatistics example 1 (Python window)

This example determines for each zone the range of cell values in the Value input raster.

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outZonalStats = ZonalStatistics("zone", "value", "valueraster", "RANGE",
                                "NODATA")
outZonalStats.save("C:/sapyexamples/output/zonestatout")
ZonalStatistics example 2 (stand-alone script)

This example determines for each zone the range of cell values in the Value input raster.

# Name: ZonalStatistics_Ex_02.py
# Description: Calculates statistics on values of a raster 
#    within the zones of another dataset.
# 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 = "zone"
zoneField = "value"
inValueRaster = "valueraster" 

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

# Execute ZonalStatistics
outZonalStatistics = ZonalStatistics(inZoneData, zoneField, inValueRaster,
                                     "RANGE", "NODATA")

# Save the output 
outZonalStatistics.save("C:/sapyexamples/output/zonestatout2")

Environments

  • Auto Commit
  • Cell Size
  • Compression
  • Current Workspace
  • Extent
  • Geographic Transformations
  • Mask
  • Output CONFIG Keyword
  • Output Coordinate System
  • Parallel Processing Factor
  • Raster Statistics
  • Scratch Workspace
  • Snap Raster
  • Tile Size

Licensing Information

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

Related Topics

  • An overview of the zonal tools
Feedback on this topic?

ArcGIS for Desktop

  • Home
  • Documentation
  • Pricing
  • Support

ArcGIS Platform

  • ArcGIS Online
  • ArcGIS for Desktop
  • ArcGIS for Server
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Insiders Blog
  • User Conference
  • Developer Summit
Esri
© Copyright 2016 Environmental Systems Research Institute, Inc. | Privacy | Legal