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

• 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

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}, {CELL | MAP}) NbrCircle({radius}, {CELL | MAP} NbrRectangle({width}, {height}, {CELL | MAP}) NbrWedge({radius}, {start_angle}, {end_angle}, {CELL | MAP}) NbrIrregular(kernel_file) NbrWeight(kernel_file) 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. 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 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 the processing cell will be 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
# Author: ESRI

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

## Licensing Information

ArcView: Requires Spatial Analyst
ArcEditor: Requires Spatial Analyst
ArcInfo: Requires Spatial Analyst

6/29/2011