Available with Spatial Analyst license.
Summary
Creates a table and a histogram graph that show the frequency distribution of cell values on the Value input for each unique Zone.
Illustration
Usage
A zonal histogram enables you to investigate the frequency distribution of values in one dataset within classes of another dataset. Examples include slope distribution within land use classes, rainfall distribution within elevation classes, or crime distribution by police beat.
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.
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.
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.
The Zone field must be either integer or string type.
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.
The cells on the input value raster belong to the zone that their cell centers fall within. In this case the zones are the zones after any necessary conversion to raster and resampling has taken place.
In the histogram graph, the number of classes (bins) for each zone is determined by the Input value raster.
- If a layer is specified, then the layer's symbology defines the number of classes.
- If a dataset is specified, by default there will be 256 classes, unless the input is integer with less than 26 unique values, in which case it will be the total count of unique values.
A zonal histogram graph is not generated by default. To have it be created when the tool is run, specify the Output graph name.
The graph is temporary (in-memory) only. To make a permanent version of it, use the Save Graph tool to create a .grf graph file, or one of the other output formats available in that tool.
See Analysis environments and Spatial Analyst for additional details on the geoprocessing environments that apply to this tool.
Syntax
ZonalHistogram (in_zone_data, zone_field, in_value_raster, out_table, {out_graph})
Parameter | Explanation | Data 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 | The raster values to create the histograms. | Raster Layer |
out_table | The output table file. 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. The optional graph output is created from the information in the table. | Table |
out_graph (Optional) | The name of the output graph for display. The graph is temporary. To persist it, use the Save Graph tool. | Graph |
Code sample
ZonalHistogram example 1 (Python window)
This example creates a zonal histogram .dbf table.
import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outZonHisto = ZonalHistogram("zoneras", "zonfield", "valueras", "znhist_tbl.dbf")
ZonalHistogram example 2 (stand-alone script)
This example creates a zonal histogram .dbf table and a graph file.
# Name: ZonalHistogram_Ex_02.py
# Description: Creates a zonal histogram output table and
# a graph showing the amount of value cells
# for each unique input zone.
# 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 = "zonras"
zoneField = "zonfield"
inValueRaster = "valueras"
outTable = "C:/sapyexamples/output/zonehist_tbl.dbf"
outGraph = "zonehist_gra"
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# Execute ZonalHistogram
ZonalHistogram(inZoneData, zoneField, inValueRaster, outTable, outGraph)
Environments
Licensing information
- ArcGIS Desktop Basic: Requires Spatial Analyst
- ArcGIS Desktop Standard: Requires Spatial Analyst
- ArcGIS Desktop Advanced: Requires Spatial Analyst