Block Statistics (Spatial Analyst)
Summary
Partitions the input into non-overlapping blocks and calculates the statistic of the values within each block. The value is assigned to all of the cells in each block in the output.
Illustration
![]() |
OutRas = BlockStatistics(InRas1, NbrRectangle(3,3,MAP), "MAXIMUM", "") |
Usage
-
If the input raster is of floating-point type, only the Mean, Maximum, Minimum, Range, STD, and Sum statistics are available; the Majority, Minority, Median, and Variety statistics are not permitted. If the input raster is of integer type, all the statistics types are available.
-
When a circular, annulus-shaped, or wedge-shaped neighborhood is specified, depending on the size of the neighborhood, cells that are not perpendicular to the x- or y-axis may not be considered in the calculations. However, these cell locations will receive the resulting value from the calculations of the neighborhood because they fall within the minimum-bounding rectangle (or the output block) of these circular neighborhood types.
-
If the input raster is integer, the output raster will be integer. An exception is for the Mean or STD statistics types, for which the output raster will always be floating point. If the input type is float, the output will be float for all of the available statistics types.
-
The Irregular and Weight Neighborhood types require a Kernel file be specified. Kernel files should have a .txt file extension.
See the Irregular and Weight sections of How Block Statistics works for information on creating and using kernel files.
-
For statistics type Median, if the number of cells in the block is odd, the values are ranked and the middle value is reported as the median and is an integer. If the number of cells in the block is even, the values are ranked and the middle two values are averaged to the nearest integer.
-
For statistics type Majority, cells where there is no single majority value—that is, two or more values within a block are tied as having the most number of cells with the value—will be assigned NoData. For statistics type Minority, cells where there is no single minority value will also be assigned NoData.
-
When the Statistic type is Mean, Minority, Standard Deviation, or Sum, the Neighborhood type can be set to Weight.
Syntax
Parameter | Explanation | Data Type |
in_raster |
The raster on which to perform the Block Statistics calculations. | Raster Layer |
neighborhood (Optional) |
The Neighborhood class dictates the shape of the area around each cell used to calculate the statistic. The different types of neighborhood available are NbrAnnulus, NbrCircle, NbrRectangle, NbrWedge, NbrIrregular, and NbrWeight. The following are the forms of the neighborhoods:
The {CELL | MAP} parameter defines the distance units as either being Cell units or Map units. The default neighborhood is a square NbrRectangle with a width and height of 3 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 |
Return Value
Name | Explanation | Data Type |
out_raster |
The output block statistics raster. | Raster |
Code Sample
This sample calculates the minimum cell value within each non-overlapping annulus (doughnut-shaped) neighborhood in the input GRID raster.
import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
nbr = NbrAnnulus(1, 3, "MAP")
outBlockStat = BlockStatistics("block", nbr, "MINIMUM", "")
outBlockStat.save("C:/sapyexamples/output/blockstat")
This sample calculates the minimum cell value within each non-overlapping annulus (doughnut-shaped) neighborhood in the input GRID raster.
# Name: BlockStatistics_Ex_02.py
# Description: Calculates statistics for a nonoverlapping
# 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 = "block"
nbr = NbrAnnulus(1, 3, "MAP")
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# Execute BlockStatistics
outBlockStat = BlockStatistics(inRaster, nbr, "MINIMUM", "NODATA")
# Save the output
outBlockStat.save("C:/sapyexamples/output/blockstat")