raster_tools.pad#

raster_tools.pad(raster, target, *, fill_values=None)[source]#

Pad a raster’s grid out to cover the given extent.

The source raster’s grid (resolution and origin) is preserved; only new cells are added on the edges. If the requested extent is already inside the raster, the result is unchanged in shape.

Parameters
  • raster (str, Raster) – The raster to pad.

  • target (tuple, Raster, or odc.geo.geobox.GeoBox) –

    The extent to pad to. Accepts:

    • a (minx, miny, maxx, maxy) tuple in the raster’s CRS (pixel-edge semantics, matching Raster.bounds)

    • a Raster – its .bounds is used; its resolution and origin are ignored

    • a GeoBox – its bounding box is used

  • fill_values (None, scalar, or list of scalars, optional) –

    Value(s) used to fill newly added cells.

    • None (default): use the raster’s null value, and mark the new cells as null. If the raster has no null value, a dtype-appropriate sentinel is chosen and assigned to the result.

    • scalar: fill all new cells across all bands with this value. If the value equals the raster’s null value, behave as None for that case.

    • list/tuple of length nbands: per-band fill. Per-band values that equal the raster’s null value cause those bands’ new cells to be marked null.

Returns

A new lazy Raster covering at least the requested extent.

Return type

Raster