Vous êtes sur la page 1sur 7

Page 1 of 7

Zonal Statistics as Table (Spatial Analyst)

Title Zonal Statistics as Table (Spatial Analyst)

Summary
Summarizes the values of a raster within the zones of another dataset and reports the results to a
table.

Illustration

Usage
l 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.
l 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.
l 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.
l 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 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,
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.
l 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

file:///C:/Users/User/AppData/Local/Temp/arcFA40/tmpFC6B.tmp.htm 6/18/2018
Page 2 of 7

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 may have 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.
l 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.
l 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.
l 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.
l 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.
l If a reserved field (for example, OBECTID, FID, or OID) is selected for the Zone field, then this
may cause some ambiguity in the result. The result includes the particular reserved field name
necessary for the particular output format type, as well as the Zone field specified. If the
specified field has the same name as the reserved field for the particular output format, in the
output the name for the zone field will be altered in such a way that all field names in the result
are unique.
To make a field of unique values that does not have a reserved name, use the Add Field and
Calculate Field geoprocessing tools.
l 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.
l For majority and minority calculations, when there is a tie, the output for the zone is based on
the lowest of the tied values.
l A field or series of fields will be created in the output table, depending on the setting of the
Statistics type. When the Value input is integer, all of the statistics (Area, Min, Max, Range,
Mean, STD, Sum, Variety, Majority, Minority, and Median) are available to be calculated. If the
Value input is floating point, the Majority, Minority, Median, and Variety statistics will not be
calculated.
l 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.
l The number of rows in the output table is the number of zones.
l By default, this tool will take advantage of multi-core processors. The maximum number of cores
that can be utilized is limited to 4.
If you wish the tool to use fewer cores, use the parallelProcessingFactor environment setting.

Syntax
ZonalStatisticsAsTable_sa (in_zone_data, zone_field, in_value_raster, out_table, {ignore_nodata},
{statistics_type})

file:///C:/Users/User/AppData/Local/Temp/arcFA40/tmpFC6B.tmp.htm 6/18/2018
Page 3 of 7

Parameter Explanation Data Type

in_zone_data Dialog Reference Raster Layer |


Feature Layer
Dataset that defines the zones.
The zones can be defined by an integer raster or
a feature layer.
___________________

Python Reference
Dataset that defines the zones.
The zones can be defined by an integer raster or
a feature layer.

zone_field Dialog Reference Field


Field that holds the values that define each zone.
It can be an integer or a string field of the zone
dataset.
___________________

Python Reference
Field that holds the values that define each zone.
It can be an integer or a string field of the zone
dataset.

in_value_raster Dialog Reference Raster Layer


Raster that contains the values on which to
calculate a statistic.
___________________

Python Reference
Raster that contains the values on which to
calculate a statistic.

out_table Dialog Reference Table


Output table that will contain the summary of the
values in each zone.
The format of the table is determined by the
output location and path. If no extension is
specified, it will be an INFO table. If the location
is in a geodatabase, the output table will be
created in that particular type (for example, a file
or ArcSDE geodatabase). If the name has a .dbf
extension, the output will be in dBASE format.
___________________

Python Reference
Output table that will contain the summary of the
values in each zone.
The format of the table is determined by the
output location and path. If no extension is
specified, it will be an INFO table. If the location
is in a geodatabase, the output table will be
created in that particular type (for example, a file

file:///C:/Users/User/AppData/Local/Temp/arcFA40/tmpFC6B.tmp.htm 6/18/2018
Page 4 of 7

or ArcSDE geodatabase). If the name has a .dbf


extension, the output will be in dBASE format.

ignore_nodata (Optional) Dialog Reference Boolean


Denotes whether NoData values in the Value
input will influence the results of the zone that
they fall within.

l Checked—Within any particular zone, only


cells that have a value in the input Value
raster will be used in determining the
output value for that zone. NoData cells in
the Value raster will be ignored in the
statistic calculation.
l Unchecked—Within any particular zone, if
any NoData cells exist in the Value raster it
is deemed that there is insufficient
information to perform statistical
calculations for all the cells in that zone;
therefore, the entire zone will receive the
NoData value on the output raster.
___________________

Python Reference
Denotes whether NoData values in the Value
input will influence the results of the zone that
they fall within.

l DATA — Within any particular zone, only


cells that have a value in the input Value
raster will be used in determining the
output value for that zone. NoData cells in
the Value raster will be ignored in the
statistic calculation.
l NODATA — Within any particular zone, if
any NoData cells exist in the Value raster,
it is deemed that there is insufficient
information to perform statistical
calculations for all the cells in that zone;
therefore, the entire zone will receive the
NoData value on the output raster.

statistics_type (Optional) Dialog Reference String


Statistic type to be calculated.

l ALL —All of the statistics will be calculated.


This is the default.
l MEAN — Calculates the average of all cells
in the value raster that belong to the same
zone as the output cell.
l MAJORITY — Determines the value that
occurs most often of all cells in the value
raster that belong to the same zone as the
output cell.
l MAXIMUM — Determines the largest value

file:///C:/Users/User/AppData/Local/Temp/arcFA40/tmpFC6B.tmp.htm 6/18/2018
Page 5 of 7

of all cells in the value raster that belong to


the same zone as the output cell.
l MEDIAN — Determines the median value of
all cells in the value raster that belong to
the same zone as the output cell.
l MINIMUM — Determines the smallest value
of all cells in the value raster that belong to
the same zone as the output cell.
l MINORITY — Determines the value that
occurs least often of all cells in the value
raster that belong to the same zone as the
output cell.
l RANGE — Calculates the difference
between the largest and smallest value of
all cells in the value raster that belong to
the same zone as the output cell.
l STD — Calculates the standard deviation of
all cells in the value raster that belong to
the same zone as the output cell.
l SUM — Calculates the total value of all
cells in the value raster that belong to the
same zone as the output cell.
l VARIETY — Calculates the number of
unique values for all cells in the value
raster that belong to the same zone as the
output cell.
l MIN_MAX —Both the Minimum and
Maximum statistics are calculated.
l MEAN_STD —Both the Mean and STD
statistics are calculated.
l MIN_MAX_MEAN —The Minimum,
Maximum and Mean statistics are
calculated.
___________________

Python Reference
Statistic type to be calculated.

l ALL —All of the statistics will be calculated.


This is the default.
l MEAN — Calculates the average of all cells
in the value raster that belong to the same
zone as the output cell.
l MAJORITY — Determines the value that
occurs most often of all cells in the value
raster that belong to the same zone as the
output cell.
l MAXIMUM — Determines the largest value
of all cells in the value raster that belong to
the same zone as the output cell.
l MEDIAN — Determines the median value of
all cells in the value raster that belong to
the same zone as the output cell.
l MINIMUM — Determines the smallest value
of all cells in the value raster that belong to
the same zone as the output cell.

file:///C:/Users/User/AppData/Local/Temp/arcFA40/tmpFC6B.tmp.htm 6/18/2018
Page 6 of 7

l MINORITY — Determines the value that


occurs least often of all cells in the value
raster that belong to the same zone as the
output cell.
l RANGE — Calculates the difference
between the largest and smallest value of
all cells in the value raster that belong to
the same zone as the output cell.
l STD — Calculates the standard deviation of
all cells in the value raster that belong to
the same zone as the output cell.
l SUM — Calculates the total value of all
cells in the value raster that belong to the
same zone as the output cell.
l VARIETY — Calculates the number of
unique values for all cells in the value
raster that belong to the same zone as the
output cell.
l MIN_MAX —Both the Minimum and
Maximum statistics are calculated.
l MEAN_STD —Both the Mean and STD
statistics are calculated.
l MIN_MAX_MEAN —The Minimum,
Maximum and Mean statistics are
calculated.

Code Samples

ZonalStatisticsAsTable example 1 (Python window)


This example summarizes the values of a raster within the zones defined by a polygon shapefile and
records the results in a table.

import arcpy
from arcpy import env

from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outZSaT = ZonalStatisticsAsTable("zones.shp", "Classes", "valueforzone",
"zonalstattblout", "NODATA", "SUM")

 
ZonalStatisticsAsTable example 2 (stand-alone script)
This example summarizes the values of a raster within the zones defined by a polygon shapefile and
records the results in a .dbf file.

file:///C:/Users/User/AppData/Local/Temp/arcFA40/tmpFC6B.tmp.htm 6/18/2018
Page 7 of 7

# Name: ZonalStatisticsAsTable_Ex_02.py
# Description: Summarizes values of a raster within the zones of

# another dataset and reports the results to a table.
# 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 = "zones.shp"
zoneField = "Classes"
inValueRaster = "valueforzone"
outTable = "zonalstattblout02.dbf"

# Check out the ArcGIS Spatial Analyst extension license


arcpy.CheckOutExtension("Spatial")

# Execute ZonalStatisticsAsTable
outZSaT = ZonalStatisticsAsTable(inZoneData, zoneField, inValueRaster,
outTable, "NODATA", "MEAN")

 
Environments
Cell size, Current workspace, Mask, Output coordinate system, Output
extent, ParallelProcessingFactor, Scratch workspace, Snap raster

Tags
There are no tags for this item.

Credits
There are no credits for this item.

Use limitations
There are no access and use limitations for this item.

You are currently using the Item Description metadata style. Change your metadata style in the
Options dialog box to see additional metadata content.

file:///C:/Users/User/AppData/Local/Temp/arcFA40/tmpFC6B.tmp.htm 6/18/2018

Vous aimerez peut-être aussi