geoutils.operators.GridNeighbours

geoutils.operators.GridNeighbours#

class geoutils.operators.GridNeighbours(offsets=None, window_shape=None, *, size=None, shape='square', coverage='center')[source]#

Define a grid neighbourhood for source cells, i.e. a window surrounding the target cells.

Pass size for a square or circular window, or supply row/column offsets directly to define any window shape. For example, InverseDistance(neighborhood=GridNeighbours(size=5, shape="circular")) uses cells whose centers lie within 2.5 pixels of the target cell’s center. For a Reducer with coverage="fractional", a circle of the same radius is centered on the requested point.

For use with a Reducer with either a non-square window or involving area deformations through a CRS change (i.e. use in reproject()), exact area coverage can be defined according to the following options:

  • center uses all cells whose center is intersected by the window shape,

  • all_touched includes all touched cells,

  • fractional weights each cell by its area covered fraction, requiring a Reducer that supports weighting.

For built-in regular interpolation, offsets describe the method’s natural stencil: nearest uses (0, 0) relative to the nearest cell; linear/slinear use (0, 1) on each axis relative to the lower grid index, and PCHIP uses (-1, 0, 1, 2). Extra offsets warn and are ignored; missing offsets raise an error. Cubic, quintic and splinef2d fit the complete raster and do not accept GridNeighbours.

from geoutils.operators import GridNeighbours
from geoutils.operators.reducer import Mean

window = GridNeighbours(size=5, shape="circular")
values = raster.resample_at_points((x, y), Mean(neighborhood=window), as_array=True)
Parameters:
  • offsets (tuple[tuple[int, int], ...] | int | None) – Optional row/column offsets relative to the target’s containing source cell, except for the built-in regular interpolation stencils described above. An integer instead specifies the window size.

  • window_shape (Literal['square', 'circular'] | None) – Shape recorded for an existing set of offsets.

  • size (int | None) – Positive odd number of rows and columns in a centered window, used instead of offsets.

  • shape (Literal['square', 'circular']) – Include the whole square or only cells inside its centered circle when size is given.

  • coverage (Literal['center', 'all_touched', 'fractional']) – How a cells at the edge of a r window.

__init__(offsets=None, window_shape=None, *, size=None, shape='square', coverage='center')[source]#

Select a window by size or offsets and choose how source cells contribute.

Methods

__init__([offsets, window_shape, size, ...])

Select a window by size or offsets and choose how source cells contribute.

Attributes

coverage

overlap

Return how many extra rows/columns are needed on either side of a raster chunk.

window_shape

offsets