stackstac.reproject_array#
- stackstac.reproject_array(arr, spec, interpolation='nearest', fill_value=nan)#
Reproject and clip a
DataArray
to a newRasterSpec
(CRS, resolution, bounds).This interpolates using
xarray.DataArray.interp
, which usesscipy.interpolate.interpn
internally (no GDAL). It is somewhat dask-friendly, in that it at least doesn’t trigger immediate computation on the array, but it’s sub-optimal: thex
andy
dimensions are just merged into a single chunk, then interpolated.Since this both eliminates spatial parallelism, and potentially requires significant amounts of memory,
reproject_array
is only recommended on arrays with a relatively small number spatial chunks.Warning
This method is very slow on large arrays due to inefficiencies in generating the dask graphs. Additionally, all spatial chunking is lost.
- Parameters:
arr (
DataArray
) – Array to reproject. It must haveepsg
,x
, andy
coordinates. Thex
andy
coordinates are assumed to indicate the top-left corner of each pixel, not the center.spec (
RasterSpec
) – TheRasterSpec
to reproject to.interpolation (
Literal
[‘linear’, ‘nearest’]) – Interpolation method:"linear"
or"nearest"
, default"nearest"
.fill_value (
Union
[int
,float
,None
]) – Fill output pixels that fall outside the bounds ofarr
with this value (default NaN).
- Returns:
The clipped and reprojected array.
- Return type: