Zonal Statistics as Table |
|
Release 9.3
Last modified September 7, 2011 |
![]() ![]() ![]() Print all topics in : "Zonal (Spatial Analyst)" |
Summarizes the values of a raster within the zones of another dataset and reports the results to a table.
Learn more about how Zonal Statistics works
Illustration
ZonalStatisticsAsTable ZoneRas VALUE ValRas OutTable
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 of the 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), and use the resulting raster as your Zone input.If the zone input is feature dataset with 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 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 Zonal Statistics 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.
The input value raster can be either integer or floating point. However, when it is of floating-point type, the zonal calculations for majority, median, minority, and variety are not performed.
For majority and minority calculations, when there is a tie the output for the zone is based on the lowest of the tied values.
A series of fields will be created in the output table. Value, count, area, min, max, range, sum, mean, and std fields will be created regardless of the input values. Majority, minority, median, and variety fields will only be created when the input value raster is integer.
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 number of rows in the output table is the number of zones.
An example of the output table is:
VALUE COUNT AREA MEAN MIN MAX ... 0 5 125.0000 0.6 0.0 .0 ... 1 5 125.0000 1.0 0.0 3.0 ... 2 3 75.0000 1.667 1.0 2.0 ... 4 2 50.0000 3.0 3.0 3.0 ...
The following environment settings affect this tool:
ArcObjects
Zones are defined as areas that have identical values. Thus 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 contain either integer or floating-point. However, when it is of floating-point, the zonal calculations for majority, median, minority, and variety are not performed.
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 output from the ArcObjects method is a table object.
A series of fields will be created in the output table. Value, count, area, min, max, range, sum, mean, and std fields will be created regardless of the input values. Majority, minority, median, and variety fields will only be created when the input value raster is integer.
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 number of rows in the output table is the number of zones.
An example of the output table is:
VALUE COUNT AREA MEAN MIN MAX ... 0 5 125.0000 0.6 0.0 .0 ... 1 5 125.0000 1.0 0.0 3.0 ... 2 3 75.0000 1.667 1.0 2.0 ... 4 2 50.0000 3.0 3.0 3.0 ...
Command line syntax
An overview of the Command Line window
ZonalStatisticsAsTable_sa <in_zone_data> <zone_field> <in_value_raster> <out_table> {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 for which to calculate a statistic. |
Composite Geodataset |
<out_table> |
Output table that will contain the summary of the values in each zone. |
Table |
{DATA | NODATA} |
Denotes whether NoData values on the Value input will influence the results of the zone that they fall within.
|
Boolean |
ZonalStatisticsAsTable_sa c:/data/ras_1 Value c:/data/ras_2 c:/data/final_1.dbf DATA
Scripting syntax
About getting started with writing geoprocessing scripts
ZonalStatisticsAsTable_sa (in_zone_data, zone_field, in_value_raster, out_table, 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 for which to calculate a statistic. |
Composite Geodataset |
out_table (Required) |
Output table that will contain the summary of the values in each zone. |
Table |
ignore_nodata (Optional) |
Denotes whether NoData values on the Value input will influence the results of the zone that they fall within.
|
Boolean |
# ZonalStatisticsAsTable.py # Description: # Summarizes values of a raster within the zones of another # dataset and reports the results to a table.# 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 table name outTable = "c:/data/final_1.dbf" # Check out Spatial Analyst extension license gp.CheckOutExtension("Spatial") # Process: Zonal Statistics as Table cellSize = 1 gp.ZonalStatisticsAsTable_sa(inRaster1, "Value", inRaster2, outTable, "DATA") except: # If an error occurred while running a tool, then print the messages print gp.GetMessages()
Map Algebra syntax
See ZonalStats
ArcObjects syntax
IZonalOp::ZonalStatisticsAsTable (zone As IGeoDataset, value As IGeoDataset, ignoreNoData As Boolean) As ITable
Parameter | Explanation |
zone | An input Raster, RasterDataset, RasterBand, or RasterDescriptor 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. |
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 table object Dim pOutputTable As ITable ' Calls the method Set pOutputTable = pZonalOp.ZonalStatisticsAsTable _ (pZoneRaster, pValueRaster, True)