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 can be used for the zone input.
When the Cell size of the Input raster or feature zone data (in_zone_data in Python) and the Input value raster (in_value_raster in Python) is different, the output cell size will be the Maximum Of Inputs, and the Input value raster will be used as the Snap Raster internally. If the cell size is same, but the cells are not aligned, the Input value raster will be used as the snap raster internally. Either of these cases will trigger an internal resampling before the zonal operation is performed.
When the zone and value inputs are both rasters of the same cell size and the cells are aligned, they will be used directly in the tool, and will not be resampled internally during the tool execution.
If the Input raster or feature zone data (in_zone_data in Python) is a raster, it must be an integer raster.
If the Input raster or feature zone data (in_zone_data in Python) is a feature, it will be converted to a raster internally, using the cell size and cell alignment from the Input value raster (in_value_raster in Python).
If the Input raster or feature zone data (in_zone_data in Python) is a point feature, 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 lowest ObjectID field (for example, OID or FID).
If the Input raster or feature zone data (in_zone_data in Python) 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 operation iteratively for each of the polygon zones and collate the results.
The Zone field (zone_field in Python) must be either integer or text type.
When specifying the Input raster or feature zone data (in_zone_data in Python), the default zone field will be the first available integer or text field. If no other valid fields exist, the ObjectID field (for example, OID or FID) will be the default.
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
- Basic: Requires Spatial Analyst
- Standard: Requires Spatial Analyst
- Advanced: Requires Spatial Analyst