Focal Statistics (Spatial Analyst)

Summary

Calculates for each input cell location a statistic of the values within a specified neighborhood around it.

Usage

• If the input raster is integer, all the statistics types are available. If the input raster is floating point, only the Mean, Maximum, Median, Minimum, Percentile, Range, Standard deviation, and Sum statistics are available; the Majority, Minority, and Variety statistics are not permitted.

• When a circular, an annulus-shaped, or a wedge-shaped neighborhood is specified, some of the outer diagonal cells may not be considered in the calculations because the center of the cell must be encompassed within the neighborhood.

• The Irregular and Weight Neighborhood types require that a Kernel file be specified. Kernel files should have a .txt file extension.

See the Irregular and Weight sections of Learn more about how Focal Statistics works for information on creating and using kernel files.

• The Neighborhood type can be set to Weight for the Mean, Standard Deviation, and Sum statistics types only.

• Input NoData cells may receive a value in the output if the Ignore NoData in calculations parameter is checked, provided at least one cell within the neighborhood has a valid value.

• See Analysis environments and Spatial Analyst for additional details on the geoprocessing environments that apply to this tool.

Parameters

Return Value

 Label Explanation Data Type Output raster The output focal statistics raster. Raster

`FocalStatistics(in_raster, {neighborhood}, {statistics_type}, {ignore_nodata}, {percentile_value})`

Return Value

 Name Explanation Data Type out_raster The output focal statistics raster. Raster

Code sample

FocalStatistics example 1 (Python window)

This example calculates the least-frequently occurring value in a ring-shaped neighborhood around each cell in the input raster.

``````import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outFocalStat = FocalStatistics("elevation", NbrAnnulus(5, 10, "CELL"),
"MINORITY", "NODATA")
outFocalStat.save("C:/sapyexamples/output/focalstat01")``````
FocalStatistics example 2 (stand-alone script)

This example determines the least frequently occurring value in a 10-by-10 neighborhood around each cell in the input raster.

``````# Name: FocalStatistics_Ex_02.py
# Description: Calculates a statistic on a raster over a specified
#    neighborhood.
# 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
inRaster = "elevation"
neighborhood = NbrRectangle(10, 10, "CELL")

# Execute FocalStatistics
outFocalStatistics = FocalStatistics(inRaster, neighborhood, "MINORITY",
"")

# Save the output
outFocalStatistics.save("C:/sapyexamples/output/focalstatout")``````

Licensing information

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