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.
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_rastersfunction increate.pywith a signature along the lines of:Behaviour:
np.nanmin,np.nanmax, etc.).Rastercovering the full extent.Alternatives Considered
Raster.merge()instance method — less natural since merging is N-to-1, not a transformation of a single raster.agg— could be added later, but aLiteralset covers the most common cases and keeps validation simple.Additional Context
Fits naturally in
create.pyalongside other raster-construction functions likefull_rasterandrasterize_gdf.