Zonal Statistics |
|
Release 9.2
Last modified January 3, 2008 |
![]() ![]() ![]() Print all topics in : "Zonal (Spatial Analyst)" |
Calculates statistics on values of a raster within the zones of another dataset.
Learn more about how Zonal Statistics works
Usage tips
Command line and Scripting
Zones are defined as areas that have identical values. If the zone input is a raster, it must be integer. If the zone input is a feature class, the zone field must be integer. A character field is also acceptable.
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 of the Raster Analysis Environment to Minimum Of Inputs.
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 (BuildRAT) to create one.
If the zone input is 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 that 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 or Polygon To Raster (Point To Raster and Polyline To Raster also), 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 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.
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 all cell locations in the zone is assigned 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.
The following environment settings affect this tool:
ArcObjects
Zones are defined as areas that have identical values. If the zoneDataset input is a raster, it must be integer. If the zoneDataset input is a feature class, the zone field must be integer. A character field is also acceptable.
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 of the Analysis Environment to Minimum Of Inputs.
If the zoneDataset input is a raster, 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 BuildAttributeTable in IRasterDatasetEdit2 to create one.
If the zone input is feature dataset, internally a vector-to-raster conversion will be applied to it. To ensure that the results of the conversion will align properly with the value raster, it is recommended to ensure that the extent and snap raster are set appropriately.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, and create an attribute table as described in the previous tip.
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.
The valueDataset can be either integer or floating-point. However, when it is of 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 all cell locations in the zone is assigned the lowest of the tied values.
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 output from the ArcObjects method is a raster object.
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.
|
String |
{DATA | NODATA} |
Denotes whether NoData values on the Value input will influence the results of the zone that they fall within.
|
Boolean |
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.
|
String |
ignore_nodata (Optional) |
Denotes whether NoData values on the Value input will influence the results of the zone that they fall within.
|
Boolean |
# 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:
|
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. |
' 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)