Focal Statistics |
|
|
Release 9.3
Last modified September 7, 2011 |
Print all topics in : "Neighborhood (Spatial Analyst)" |
Calculates a statistic on a raster over a specified neighborhood.
Learn more about how Focal Statistics works
Usage tips
Command line and Scripting
The values on the output raster depend on the operation.
When a circular, annulus-shaped, or wedge-shaped neighborhood is specified, and the center of the cell must be encompassed within the neighborhood, some of the outer diagonal cells may not be considered in the calculations. However, these cell locations will receive the resulting value from the calculations because they fall within the minimum-bounding rectangle (or the output neighborhood) of the three circular-type neighborhoods.
The Irregular and Weight neighborhood types require a Kernel file. Kernel files should have a ".txt" file extension. See the Irregular and Weight sections of How Focal Statistics works for information on creating and using kernel files.
Only for the statistics types of mean, standard deviation and sum can the Neighborhood type be set to Weight.
The following environment settings affect this tool:
ArcObjects
When a circular, annulus-shaped, or wedge-shaped neighborhood is specified, and the center of the cell must be encompassed within the neighborhood, some of the outer diagonal cells may not be considered in the calculations. However, these cell locations will receive the resulting value from the calculations because they fall within the minimum-bounding rectangle (or the output neighborhood) of the three circular neighborhoods.
The output from the ArcObjects method is a raster object.
See the individual corresponding Map Algebra Focal function for the specific behavior of any statistic.
Command line syntax
An overview of the Command Line window
FocalStatistics_sa <in_raster> <out_raster> {neighborhood} {MEAN | MAJORITY | MAXIMUM | MEDIAN | MINIMUM | MINORITY | RANGE | STD | SUM | VARIETY} {DATA | NODATA}
| Parameter | Explanation | Data Type |
| <in_raster> |
The raster to perform the Focal Statistics calculations on. |
Composite Geodataset |
| <out_raster> |
The raster to be created. |
Raster Dataset |
| {neighborhood} |
Dictates the shape of the area around each cell used to calculate the statistic.
The default neighborhood is a square RECTANGLE with a width and height of three cells. |
Neighborhood |
| {MEAN | MAJORITY | MAXIMUM | MEDIAN | MINIMUM | MINORITY | RANGE | STD | SUM | VARIETY} |
The statistic type to be calculated.
The default statistic type is Mean. |
String |
| {DATA | NODATA} |
Denotes whether NoData values are ignored by the statistic calculation.
|
Boolean |
FocalStatistics_sa C:/data/raster1 C:/data/focalstat "Rectangle 5 6 Map" DATA
Scripting syntax
About getting started with writing geoprocessing scripts
FocalStatistics_sa (in_raster, out_raster, neighborhood, statistics_type, ignore_nodata)
| Parameter | Explanation | Data Type |
| in_raster (Required) |
The raster to perform the Focal Statistics calculations on. |
Composite Geodataset |
| out_raster (Required) |
The raster to be created. |
Raster Dataset |
| neighborhood (Optional) |
Dictates the shape of the area around each cell used to calculate the statistic.
The default neighborhood is a square RECTANGLE with a width and height of three cells. |
Neighborhood |
| statistics_type (Optional) |
The statistic type to be calculated.
The default statistic type is Mean. |
String |
| ignore_nodata (Optional) |
Denotes whether NoData values are ignored by the statistic calculation.
|
Boolean |
# FocalStatistics_sample.py
# Description:
# Calculates a statistic on a raster over a specified neighborhood.
# Requirements: None
# Author: ESRI
# Date: Sept 6, 2005
# Import system modules
import arcgisscripting
# Create the Geoprocessor object
gp = arcgisscripting.create()
try:
# Set local variables
InRaster = "C:/data/raster1"
OutRaster = "C:/data/focalstat"
InNeighborhood = "Rectangle 5 6 Map"
InNoDataOption = "DATA"
# Check out Spatial Analyst extension license
gp.CheckOutExtension("Spatial")
# Process: FocalStatistics
gp.FocalStatistics_sa(InRaster, OutRaster, InNeighborhood, "", InNoDataOption)
except:
# If an error occurred while running a tool, then print the messages.
print gp.GetMessages()
Map Algebra syntax
See FocalMajority, FocalMax, FocalMean, FocalMedian, FocalMin, FocalMinority, FocalRange, FocalStd, FocalSum, FocalVariety, depending on the desired Focal statistic.
ArcObjects syntax
INeighborhoodOp::FocalStatistics (geoDataset As IGeoDataset, type As esriGeoAnalysisStatisticsEnum, nbrhood As IRasterNeighborhood, ignoreNoData As Boolean) As IGeoDataset
| Parameter | Explanation |
| geoDataset | An input Raster, RasterDataset, RasterBand, or RasterDescriptor that identifies the values of the focal or processing cell and the values of the cells in its specified neighborhood. |
| type | An esriGeoAnalysisStatisticsEnum defining the focal statistic to calculate within each neighborhood.
The enumeration types are:
|
| nbrhood | A RasterNeighborhood defining the configuration of the neighborhoods within which the focal statistics will be calculated.
INeighborhoodOp::FocalStatistics supports any neighborhood supported by RasterNeighborhood, such as rectangle, circle, annulus, wedge, and an irregularly-shaped neighborhood. The neighborhood will be defined by the minimum-bounding rectangle of the specified neighborhood. The minimum-bounding rectangle will include more cells than the specified neighborhood in certain cases, such as with a circle, annulus, and wedge. |
| ignoreNoData | A Boolean defining the manner in which NoData values within a neighborhood will influence the output results.
If True, and if a NoData value exists within the neighborhood of the processing cell, the NoData value will be ignored. Only cells within the neighborhood that have data values will be used in determining the statistic. If False, and if any cell in a neighborhood has a value of NoData, the output for the processing cell of the neighborhood will be NoData. When False, the presence of a NoData value implies that there is insufficient information to determine the statistic of the values of the neighborhood. |
' Create the RasterNeighborhoodOp object
Dim pNbrOp As INeighborhoodOp
Set pNbrOp = New RasterNeighborhoodOp
' Create the neighborhood object
Dim pNbr As IRasterNeighborhood
Set pNbr = New RasterNeighborhood
pNbr.SetCircle 3, esriUnitsCells
' Call a function to open a raster dataset
Dim pInputDataset As IGeoDataset
Set pInputDataset = OpenRasterDataset ("D:\SpatialData\", "inputraster")
' Create output using the method
Dim pOutputRaster As IRaster
Set pOutputRaster = pNbrOp.FocalStatistics(pInputDataset, _
esriGeoAnalysisStatsMajority, pNbr, False)