xrspatial.reproject.merge#
- xrspatial.reproject.merge(rasters, *, target_crs=None, resolution=None, bounds=None, resampling='bilinear', nodata=None, strategy='first', chunk_size=None, transform_precision=16, name=None, bounds_policy='auto')[source]#
Merge multiple rasters into a single mosaic.
Each input is reprojected to the target CRS (if needed) and placed into a unified output grid. Overlapping regions are resolved using the selected strategy.
- Parameters:
rasters (list of xr.DataArray) – Input rasters to merge.
target_crs (optional) – Target CRS. Defaults to the CRS of the first raster.
resolution (float or (float, float) or None) – Output resolution in target CRS units.
bounds ((left, bottom, right, top) or None) – Explicit output extent.
resampling (str) – Interpolation method: ‘nearest’, ‘bilinear’, ‘cubic’.
nodata (float or None) – Nodata value for the output.
strategy (str) – Merge strategy: ‘first’, ‘last’, ‘mean’, ‘max’, ‘min’.
chunk_size (int or (int, int) or None) – Output chunk size for dask. If None, defaults to 512 for the standard dask path and 2048 for the in-memory streaming and dask+cupy paths (chosen to amortize kernel launch overhead).
transform_precision (int) – Control-grid subdivisions for the coordinate transform (default 16). Higher values increase accuracy at the cost of more pyproj calls. Set to 0 for exact per-pixel transforms matching GDAL/rasterio.
name (str or None) – Name for the output DataArray.
bounds_policy ({"auto", "raw", "clamp", "percentile"}, default "auto") – How to derive the unified output extent from the input rasters when
boundsis not supplied. Seereproject()for the full description of each option. Ignored whenboundsis given.
- Returns:
The output y coordinate is always emitted in descending order (top-down, north-up) regardless of the input direction. This matches the standard raster convention and the output of common GIS libraries.
Non-spatial coords from the first raster (such as a scalar
timecoord) are carried through to the output. Coords aligned to the spatial dims are dropped because their values do not apply to the merged grid.- Return type:
xr.DataArray
Notes
There is no streaming in-memory path; for very large output mosaics, pass dask-backed inputs (or rely on the automatic promotion to the dask path) so that each output chunk is computed independently.
Examples
>>> import xarray as xr >>> import numpy as np >>> from xrspatial.reproject import merge >>> tile_a = xr.DataArray( ... np.full((32, 32), 1.0), dims=['y', 'x'], ... coords={'y': np.linspace(50, 45, 32), ... 'x': np.linspace(-5, 0, 32)}, ... attrs={'crs': 'EPSG:4326'}, ... ) >>> tile_b = xr.DataArray( ... np.full((32, 32), 2.0), dims=['y', 'x'], ... coords={'y': np.linspace(50, 45, 32), ... 'x': np.linspace(0, 5, 32)}, ... attrs={'crs': 'EPSG:4326'}, ... ) >>> mosaic = merge([tile_a, tile_b], resolution=0.5) >>> mosaic.shape[1] >= 32 True