Skip to content

Feature: Add merge function for combining rasters with a configurable aggregation #436

Description

@b-j-karl

Description

Add a high-level function to merge multiple rasters into a single output raster, using a user-specified aggregation function (e.g. minimum, maximum, mean) to resolve overlapping cells.

Motivation

Merging rasters is a common GIS workflow — e.g. combining tiled survey data or overlapping model outputs. Currently users must manually compute the union bounds, create a canvas, align each raster, and aggregate values cell-by-cell. A built-in function would make this straightforward.

Proposed Solution

A merge_rasters function in create.py with a signature along the lines of:

def merge_rasters(
    rasters: Collection[Raster],
    *,
    agg: Literal["min", "max", "mean", "sum"] = "min",
) -> Raster:

Behaviour:

  • Compute the union of all input bounding boxes to define the output extent.
  • Use the cell size and CRS from the first raster (all inputs must share the same CRS and cell size).
  • Stack aligned arrays and apply the aggregation function, treating NaN as missing (i.e. np.nanmin, np.nanmax, etc.).
  • Return a single Raster covering the full extent.

Alternatives Considered

  • A Raster.merge() instance method — less natural since merging is N-to-1, not a transformation of a single raster.
  • Accepting an arbitrary callable for agg — could be added later, but a Literal set covers the most common cases and keeps validation simple.

Additional Context

Fits naturally in create.py alongside other raster-construction functions like full_raster and rasterize_gdf.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions