xrspatial.resample.resample#

xrspatial.resample.resample(agg, scale_factor=None, target_resolution=None, method='nearest', name='resample')[source]#

Change raster resolution without changing its CRS.

Exactly one of scale_factor or target_resolution must be given.

Parameters:
  • agg (xarray.DataArray) – Input raster (2-D).

  • scale_factor (float or (float, float), optional) – Multiplicative factor applied to the number of pixels. 0.5 halves the pixel count (doubles the cell size); 2.0 doubles the pixel count (halves the cell size). A two-element tuple sets (scale_y, scale_x) independently.

  • target_resolution (float, optional) – Desired cell size in the same units as the raster coordinates. Both axes are set to this resolution.

  • method (str, default 'nearest') – Resampling algorithm. Interpolation methods ('nearest', 'bilinear', 'cubic') work for both upsampling and downsampling. Aggregation methods ('average', 'min', 'max', 'median', 'mode') only support downsampling (scale_factor <= 1).

  • name (str, default 'resample') – Name for the output DataArray.

Returns:

Resampled raster with updated coordinates, res attribute, and float32 dtype.

Return type:

xarray.DataArray