geo-registry

Focal Statistics

Each cell gets a statistic (mean, sum, minimum, ...) of the cells in a window around it.

Pitfall. Cells near the edge have incomplete windows; engines use the partial window, return nodata, or pad.
About this operation
Also called neighborhood statistics, moving window, mean filter, focal mean, r.neighbors
Group raster/neighborhood
Checks raster.nodata
Pitfalls 1 listed above
Columbus tool Not stated
Notes Not stated
Status active
Broader Not stated
Narrower Not stated
Related

Parameters

Name Type Required Default Values Note
statistic enum no mean mean, sum, min, max, median, std Not stated
size integer no 3 Not stated Window width in cells (an odd number).

Inputs and outputs

Direction Name Type Geometry Note
Input raster raster Not stated Not stated
Output output raster Not stated Not stated

In each engine

Engine Tool Parameters Differences
gdal gdal raster neighbors
  • statistic → method : mean = mean; sum = sum; min = min; max = max; median = median; std = stddev
  • size → size
  • raster → input
  • output → output
  • kernel is required; equal (all weights 1) gives the plain window statistic.
  • kernel gives other weights (a Gaussian, edge detection) or a custom matrix.
Preset: {"kernel":"equal"}
grass r.neighbors
  • statistic → method : mean = average; sum = sum; min = minimum; max = maximum; median = median; std = stddev
  • size → size
  • raster → input
  • output → output
  • The c flag uses a circular window.
terra terra::focal
  • statistic → fun : mean = mean; sum = sum; min = min; max = max; median = median; std = sd
  • size → w
  • raster → x
  • fun defaults to sum; w can also be a weights matrix.
whiteboxtools MeanFilter
  • statistic always mean. Other filters are separate tools (MedianFilter, MaximumFilter, ...).
  • size filterx and filtery: the window's width and height in cells.
  • raster → input
  • output → output
None noted
xarray-spatial xrspatial.focal.focal_stats
  • statistic → stats_funcs : A list of statistic names.
  • size kernel: an array, e.g. from xrspatial.convolution.circle_kernel or a square of ones.
  • raster → agg
None noted