Zonal Histogram (Spatial Analyst)

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.

Usage

  • A zonal histogram allows 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.

  • 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).

  • 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 value, and the Input value raster will be used as the snap raster internally. If the cell size is the 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 tool execution.

  • 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 have only 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 parameter (zone_field in Python) value 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.

  • A zonal histogram graph is not generated by default. To create the graph, check the Zones as rows in output table parameter (set the zones_as_rows parameter to ZONES_AS_ROWS in Python) and specify an Output graph name (out_graph parameter in Python). The zonal histogram graph can only be created within the ArcGIS Pro application and is not supported from a stand-alone script.

  • In the histogram graph, the number of classes (bins) for each zone is determined by the Input value raster parameter.

    • If a layer is specified, 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 the number of classes will be the total count of unique values.

  • 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}, {zones_as_rows})
ParameterExplanationData Type
in_zone_data

The dataset that defines the zones.

The zones can be defined by an integer raster or a feature layer.

Raster Layer; Feature Layer
zone_field

The field that contains 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 that contains the values used to create the histogram.

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 in a geodatabase workspace, and a dBASE table if in a file workspace.

The optional graph output is created from the information in the table.

Table
out_graph
(Optional)

The name of the output graph for display.

Graph
zones_as_rows
(Optional)

Specifies how the values from the input value raster will be represented in the output table.

  • ZONES_AS_FIELDSZones will be represented as fields. This is the default.
  • ZONES_AS_ROWSZones will be represented as rows.
Boolean

Code sample

ZonalHistogram example 1 (Python window)

This example creates a zonal histogram .dbf table and a graph file.

from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outZonalHist = ZonalHistogram("zoneras", "zonfield", "valueras", "znhist_tbl.dbf",
                              "znhist_graphl", "ZONES_AS_ROWS")
ZonalHistogram example 2 (stand-alone script)

This example creates a zonal histogram .dbf table.

# Name: ZonalHistogram_Ex_02.py
# Description: Creates a zonal histogram output table
#              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 *

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

# Set environment settings
env.workspace = "C:/sapyexamples/data"

# Set local variables
inZoneData = "zonras"
zoneField = "zonfield"
inValueRaster = "valueras" 
outTable = "C:/sapyexamples/output/zonehist_tb2.dbf" 

# Execute ZonalHistogram
ZonalHistogram(inZoneData, zoneField, inValueRaster, outTable)

Licensing information

  • Basic: Requires Spatial Analyst
  • Standard: Requires Spatial Analyst
  • Advanced: Requires Spatial Analyst

Related topics