⚠️ Our 0.1 release refactored several early-development functions for long-term stability, to update your code see here. ⚠️
Future changes will come with deprecation warnings! 🙂

geoutils.raster.merge_rasters

Contents

geoutils.raster.merge_rasters#

geoutils.raster.merge_rasters(rasters, reference=0, merge_algorithm=<function nanmean>, resampling_method='bilinear', use_ref_bounds=False, progress=True)[source]#

Spatially merge a list of rasters into one larger raster of their maximum extent.

The input rasters can have any transform or CRS, and will be reprojected to the reference raster’s CRS and resolution. The output merged raster has an extent that is the union of all raster extents, except if use_ref_bounds is used.

Note that all rasters will be loaded once in memory. The data is only loaded for reprojection then deleted to optimize memory usage.

Parameters:
  • rasters (list[TypeVar(RasterType, bound= Raster)]) – List of rasters to be merged.

  • reference (int | Raster) – Index of reference raster in the list or separate reference raster. Defaults to the first raster in the list.

  • merge_algorithm (Union[Callable, list[Callable]]) – Reductor function (or list of functions) to merge the rasters with. Defaults to the mean. If several algorithms are provided, each result is returned as a separate band.

  • resampling_method (str | Resampling) – Resampling method for reprojection.

  • use_ref_bounds (bool) – If True, will use reference bounds, otherwise will use maximum bounds of all rasters.

  • progress (bool) – If True, will display a progress bar. Default is True.

Return type:

TypeVar(RasterType, bound= Raster)

Returns:

The merged raster with same CRS and resolution (and optionally bounds) as the reference.