Block Statistics (Spatial Analyst)

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

Illustration

Block Statistics with Maximum option illustration
OutRas = BlockStatistics(InRas1, NbrRectangle(3,3,MAP), "MAXIMUM", "")

Usage

  • If the input raster is floating point, 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 integer, 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 that 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})
ParameterExplanationData 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 available neighborhood types are NbrAnnulus, NbrCircle, NbrRectangle, NbrWedge, NbrIrregular, 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 three cells.

Neighborhood
statistics_type
(Optional)

Specifies the statistic type to be calculated.

  • MEANCalculates the mean (average value) of the cells in the neighborhood.
  • MAJORITYCalculates the majority (value that occurs most often) of the cells in the neighborhood.
  • MAXIMUMCalculates the maximum (largest value) of the cells in the neighborhood.
  • MEDIANCalculates the median of the cells in the neighborhood.
  • MINIMUMCalculates the minimum (smallest value) of the cells in the neighborhood.
  • MINORITYCalculates the minority (value that occurs least often) of the cells in the neighborhood.
  • RANGECalculates the range (difference between largest and smallest value) of the cells in the neighborhood.
  • STDCalculates the standard deviation of the cells in the neighborhood.
  • SUMCalculates the sum (total of all values) of the cells in the neighborhood.
  • VARIETYCalculates the variety (the number of unique values) of the cells in the neighborhood.

The default statistic type is Mean.

String
ignore_nodata
(Optional)

Specifies whether NoData values will be ignored by the statistic calculation.

  • DATAIf 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.
  • NODATAIf any cell in a neighborhood has a value of NoData, the output for each cell in the corresponding block 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

NameExplanationData 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

Related topics