Skip To Content

# Block Statistics

Available with Spatial Analyst license.

## 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.

Learn more about how Block Statistics works

## Usage

• If the input raster is of floating-point type, only the Mean, Maximum, Minimum, Range, Standard deviation, 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.

• If the input raster is of floating point type, the output will be float for all of the available statistics types.

If the input raster is integer, the output for most statistics types will be integer. The output for the Mean or Standard deviation statistics types will always be floating point.

• 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.

• 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 the Median statistic, 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 the Majority statistic, 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 the Minority statistic, 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.

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

## Syntax

`BlockStatistics (in_raster, {neighborhood}, {statistics_type}, {ignore_nodata})`
 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, and NbrWeight.The following are the forms of the neighborhoods:NbrAnnulus({innerRadius}, {outerRadius}, {units})NbrCircle({radius}, {units}NbrRectangle({width}, {height}, {units})NbrWedge({radius}, {startAngle}, {endAngle}, {units})NbrIrregular(inKernelFile)NbrWeight(inKernelFile)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.MEAN —Calculates the mean (average value) of the cells in the neighborhood.MAJORITY —Calculates the majority (value that occurs most often) of the cells in the neighborhood.MAXIMUM —Calculates the maximum (largest value) of the cells in the neighborhood.MEDIAN —Calculates the median of the cells in the neighborhood.MINIMUM —Calculates the minimum (smallest value) of the cells in the neighborhood.MINORITY —Calculates the minority (value that occurs least often) of the cells in the neighborhood.RANGE —Calculates the range (difference between largest and smallest value) of the cells in the neighborhood.STD —Calculates the standard deviation of the cells in the neighborhood.SUM —Calculates the sum (total of all values) of the cells in the neighborhood.VARIETY —Calculates the variety (the number of unique values) of the cells in the neighborhood.The default statistic type is Mean. String ignore_nodata(Optional) Denotes whether NoData values are ignored by the statistic calculation.DATA —Specifies that if a NoData value exists within a block neighborhood, the NoData value will be ignored. Only cells within the neighborhood that have data values will be used in determining the output value. This is the default.NODATA —Specifies that if any cell in a neighborhood has a value of NoData, the output for each cell in the corresponding block will receive NoData. With this option, the presence of a NoData value implies that there is insufficient information to determine the statistic value for the neighborhood. Boolean

#### Return Value

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

## Code sample

BlockStatistics example 1 (Python window)

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")``````
BlockStatistics example 2 (stand-alone script)

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")

# Execute BlockStatistics
outBlockStat = BlockStatistics(inRaster, nbr, "MINIMUM", "NODATA")

# Save the output
outBlockStat.save("C:/sapyexamples/output/blockstat")``````

## Licensing information

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