Cell Statistics (Spatial Analyst)
Summary
Calculates a per-cell statistic from multiple rasters.
The available statistics are Majority, Maximum, Mean, Median, Minimum, Minority, Range, Standard Deviation, Sum, and Variety.
Illustration
Usage
The order of the input rasters is irrelevant for this tool.
-
For statistic types Maximum, Minimum, Mean, Median, Majority, Minority and Sum, if a single raster is used as the input, the output cell values will be the same as the input cell values. For Range and STD the output cell values will all be 0, and for Variety, all 1.
Syntax
Parameter | Explanation | Data Type |
in_rasters_or_constants [in_raster_or_constant,...] |
A list of input rasters for which a statistic will be calculated for each cell within the Analysis window. A number can be used as an input; however, the cell size and extent must first be set in the environment. | Raster Layer | Constant |
statistics_type (Optional) |
Statistic type to be calculated.
| String |
ignore_nodata (Optional) |
Denotes whether NoData values are ignored by the statistic calculation.
| Boolean |
Return Value
Name | Explanation | Data Type |
out_raster |
The output raster. The value is determined by applying the specified statistic type to the input rasters. | Raster |
Code Sample
This example calculates the standard deviation per cell on several input Grid rasters and outputs the result as an IMG raster.
import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outCellStats = CellStatistics(["degs", "negs", "cost"], "STD", "DATA")
outCellStats.save("C:/sapyexamples/output/outcellstats.img")
This example calculates the standard deviation per cell on several input Grid rasters and outputs the result as a Grid raster.
# Name: CellStatistics_Ex_02.py
# Description: Calculates a per-cell statistic from multiple rasters
# 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
inRaster01 = "degs"
inRaster02 = "negs"
inRaster03 = "cost"
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# Execute CellStatistics
outCellStatistics = CellStatistics([inRaster01, inRaster02, inRaster03], "RANGE", "NODATA")
# Save the output
outCellStatistics.save("C:/sapyexamples/output/cellstats")