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

Input and output values from the Block Statistics tool with the Maximum statistic set
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.

Parameters

LabelExplanationData Type
Input raster

The raster on which to perform the block statistics calculations.

Raster Layer
Neighborhood
(Optional)

The cells of the processing block that will be used in the statistic calculation. There are several predefined neighborhood types to choose from, or a custom kernel can be defined.

Once the neighborhood type is selected, other parameters can be set to fully define the shape, size, and units of measure. The default neighborhood is a square rectangle with a width and height of three cells.

The following are the forms of the available neighborhood types:

  • Annulus, Inner radius, Outer radius, Units type

    A torus (donut-shaped) neighborhood defined by an inner radius and an outer radius. The default annulus is an inner radius of one cell and an outer radius of three cells.

  • Circle, Radius, Units type

    A circular neighborhood with the given radius. The default radius is three cells.

  • Rectangle, Height, Width, Units type

    A rectangular neighborhood defined by height and width. The default is a square with a height and width of three cells.

  • Wedge, Radius, Start angle, End angle, Units type

    A wedge-shaped neighborhood defined by a radius, the start angle, and the end angle. The wedge extends counterclockwise from the starting angle to the ending angle. Angles are specified in degrees, with 0 or 360 representing east. Negative angles can be used. The default wedge is from 0 to 90 degrees, with a radius of three cells.

  • Irregular, Kernel file

    A custom neighborhood with specifications set by the identified kernel text file.

  • Weight, Kernel file

    A custom neighborhood with specifications set by the identified kernel text file, which can apply weights to the members of the neighborhood.

For the annulus, circle, rectangle and wedge neighborhood types, the distance units for the parameters can be specified in Cell units or Map units. Cell units is the default.

For kernel neighborhoods, the first line in the kernel file defines the width and height of the neighborhood in numbers of cells. The subsequent lines indicate how the input value that corresponds to that location in the kernel will be processed. A value of 0 in the kernel file for either the irregular or the weight neighborhood type indicates the corresponding location will not be included in the calculation. For the irregular neighborhood, a value of 1 in the kernel file indicates that the corresponding input cell will be included in the operation. For the weight neighborhood, the value at each position indicates what the corresponding input cell value is to be multiplied by. Positive, negative, and decimal values can be used.

Neighborhood
Statistics type
(Optional)

Specifies the statistic type to be calculated.

  • Mean —The mean (average value) of the cells in the neighborhood will be calculated.
  • Majority —The majority (value that occurs most often) of the cells in the neighborhood will be identified.
  • Maximum —The maximum (largest value) of the cells in the neighborhood will be identified.
  • Median —The median of the cells in the neighborhood will be calculated.
  • Minimum —The minimum (smallest value) of the cells in the neighborhood will be identified.
  • Minority —The minority (value that occurs least often) of the cells in the neighborhood will be identified.
  • Range —The range (difference between largest and smallest value) of the cells in the neighborhood will be calculated.
  • Standard deviation —The standard deviation of the cells in the neighborhood will be calculated.
  • Sum —The sum of the cells in the neighborhood will be calculated.
  • Variety —The variety (the number of unique values) of the cells in the neighborhood will be calculated.
String
Ignore NoData in calculations
(Optional)

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

  • Checked—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.
  • Unchecked—If any cell in a block neighborhood has a value of NoData, the output for each cell in the corresponding block will be NoData. If this parameter is not checked, the presence of a NoData value implies that there is insufficient information to determine the statistic value for the neighborhood.
Boolean

Return Value

LabelExplanationData Type
Output raster

The output block statistics raster.

Raster

BlockStatistics(in_raster, {neighborhood}, {statistics_type}, {ignore_nodata})
NameExplanationData Type
in_raster

The raster on which to perform the block statistics calculations.

Raster Layer
neighborhood
(Optional)

The cells of the processing block that will be used in the statistic calculation. There are several predefined neighborhood types to choose from, or a custom kernel can be defined.

Once the neighborhood type is selected, other parameters can be set to fully define the shape, size, and units of measure. The default neighborhood is a square rectangle with a width and height of three cells.

The shape of the neighborhoods are defined by the Neighborhood class. The available neighborhood types are NbrAnnulus, NbrCircle, NbrRectangle, NbrWedge, NbrIrregular, and NbrWeight.

The following are the forms of the available neighborhood types:

  • NbrAnnulus({innerRadius}, {outerRadius}, {units})

    A torus (donut-shaped) neighborhood defined by an inner radius and an outer radius. The default annulus is an inner radius of one cell and an outer radius of three cells.

  • NbrCircle({radius}, {units}

    A circular neighborhood with the given radius. The default radius is three cells.

  • NbrRectangle({width}, {height}, {units})

    A rectangular neighborhood defined by height and width. The default is a square with a height and width of three cells.

  • NbrWedge({radius}, {startAngle}, {endAngle}, {units})

    A wedge-shaped neighborhood defined by a radius, the start angle, and the end angle. The wedge extends counterclockwise from the starting angle to the ending angle. Angles are specified in degrees, with 0 or 360 representing east. Negative angles can be used. The default wedge is from 0 to 90 degrees, with a radius of three cells.

  • NbrIrregular(inKernelFile)

    A custom neighborhood with specifications set by the identified kernel text file.

  • NbrWeight(inKernelFile)

    A custom neighborhood with specifications set by the identified kernel text file, which can apply weights to the members of the neighborhood.

For the NbrAnnulus, Nbrcircle, NbrRectangle and NbrWedge neighborhoods, the distance units for the parameters can be specified in CELL units or MAP units. Cell units is the default.

For kernel neighborhoods, the first line in the kernel file defines the width and height of the neighborhood in numbers of cells. The subsequent lines indicate how the input value that corresponds to that location in the kernel will be processed. A value of 0 in the kernel file for either the irregular or the weight neighborhood type indicates the corresponding location will not be included in the calculation. For the irregular neighborhood, a value of 1 in the kernel file indicates that the corresponding input cell will be included in the operation. For the weight neighborhood, the value at each position indicates what the corresponding input cell value is to be multiplied by. Positive, negative, and decimal values can be used.

Neighborhood
statistics_type
(Optional)

Specifies the statistic type to be calculated.

  • MEANThe mean (average value) of the cells in the neighborhood will be calculated.
  • MAJORITYThe majority (value that occurs most often) of the cells in the neighborhood will be identified.
  • MAXIMUMThe maximum (largest value) of the cells in the neighborhood will be identified.
  • MEDIANThe median of the cells in the neighborhood will be calculated.
  • MINIMUMThe minimum (smallest value) of the cells in the neighborhood will be identified.
  • MINORITYThe minority (value that occurs least often) of the cells in the neighborhood will be identified.
  • RANGEThe range (difference between largest and smallest value) of the cells in the neighborhood will be calculated.
  • STDThe standard deviation of the cells in the neighborhood will be calculated.
  • SUMThe sum of the cells in the neighborhood will be calculated.
  • VARIETYThe variety (the number of unique values) of the cells in the neighborhood will be calculated.

The default statistic type is MEAN.

If the input raster is integer, all the statistics types are available. If the input raster is floating point, only the MEAN, MAXIMUM, MINIMUM, RANGE, STD, and SUM statistic types are available.

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 block 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