# Calculating statistics for overlapping and non-overlapping neighborhoods

The neighborhood operations calculate output values by calculating a specified statistic to all the input cells that are contained in each neighborhood. The neighborhood is a moving window that iterates through the input data.

There are two basic kinds of neighborhood operations in Spatial Analyst: the operations where the neighborhoods of the processing locations overlap and those where the neighborhoods do not overlap.

The Focal Statistics tool processes the input dataset with overlapping neighborhoods. The Block Statistics tool processes data with neighborhoods that do not overlap.

In the focal operation, only the processing cells receive the result of the calculation of all the cells in the neighborhood, whereas in the block operation, every cell within the minimum bounding rectangle that contains the neighborhood receives the same output value.

## Neighborhood shape

The defined neighborhood shapes that can be specified are a rectangle of any dimension, a circle of any radius, an annulus (a doughnut shape) of any radius, and a wedge in any direction.

In addition to these geometric shapes, you can also create an irregularly shaped neighborhood, often called a kernel, where you can control exactly which cells in the neighborhood will be included in the calculations. Further, you can also apply different weights to specific cells in the neighborhood.

Cells in the input raster that fall within the specified neighborhood will be included in the calculations being performed for that neighborhood.

The following lists some details about the different neighborhood shapes:

- Rectangle
The width and height units of a rectangular neighborhood can be in cells or map units. The default is a neighborhood of 3 x 3 cells.

- Circle
The size of the circle depends on the specified radius. The radius is identified in cells or map units, measured perpendicular to the x- or y-axis.

When the radius is defined in map units, additional logic is employed to determine which cells are included in the processing of the neighborhood. First, the exact area of a circle defined by the specified radius value is calculated. Next, the area is calculated for two additional circles, one where the specified radius value is rounded down and one rounded up. These two areas are compared to that resulting from the specified radius, and for whichever one is closest, that radius will be used in the operation.

- Annulus
Cells that fall within the annulus will be included in the processing of the neighborhood. The inner radius specifies the radius of the inner circle of the annulus from the center of the processing cell. Any cell falling within the inner radius will not be included in the processing of the neighborhood. The outer radius specifies the radius of the outer circle of the annulus from the center of the processing cell. The outer circle defines the extent of the neighborhood. Any cell center falling within the radius of the outer circle but outside the radius of the inner circle will be included in the processing of the neighborhood. The radius is identified in cells or map units, measured perpendicular to the x- or y-axis.

- Wedge
Cells that fall within the wedge will be included in the processing of the neighborhood. The wedge is created by specifying a radius and an angle. The radius is specified in either cell or map units, from the center of the processing cell, measured perpendicular to the x- or y-axis.

The start angle for the wedge can be an integer or floating-point value from 0 to 360. Values for the wedge begin at 0 on the positive x-axis and increase counterclockwise until they return full circle to 0. The end angle for the wedge can be an integer or floating-point value from 0 to 360. The angle defined by the start and end values is used to create the wedge. All cells that fall within the wedge are included in the processing of the neighborhood.

- Irregular
Cells identified in the kernel with a value of 1 will be included in the processing of the neighborhood, and cells with 0 will not. The kernel is an ASCII text file that can be created with any text editor.

- Weight
Similar to the irregular neighborhood type, the kernel for the weight neighborhood is defined by an ASCII text file. The difference is that the values at the cell locations identified in the kernel will be multiplied by the value in the kernel. To have a particular location in the kernel not be included in the analysis, use a value of 0 for it.

## Types of neighborhood statistics

Various statistics can be computed on the cell values within the neighborhood being processed:

- For Focal Statistics, the result of the calculation is applied only to locations corresponding to the processing cell on the output raster.
- For Block Statistics, the result of the calculation is applied to all cells that are within the processing neighborhood.

Statistic |
Description |
---|---|

Majority |
Determines the value that occurs most often in the neighborhood |

Maximum |
Determines the maximum value in the neighborhood |

Mean |
Computes the mean of the values in the neighborhood |

Median |
Computes the median of the values in the neighborhood |

Minimum |
Determines the minimum value in the neighborhood |

Minority |
Determines the value that occurs least often in the neighborhood |

Range |
Determines the range of values in the neighborhood |

Standard deviation |
Computes the standard deviation of the values in the neighborhood |

Sum |
Computes the sum of the values in the neighborhood |

Variety |
Determines the number of unique values in the neighborhood |