Skip to content

Instantly share code, notes, and snippets.

@j08lue
Created October 5, 2017 12:21
Show Gist options
  • Save j08lue/00e3a1bf6b648fe19900159631fd946a to your computer and use it in GitHub Desktop.
Save j08lue/00e3a1bf6b648fe19900159631fd946a to your computer and use it in GitHub Desktop.
rasterio reproject array to array and write to disk
dst_crs = ...
nbands, height, width = data.shape
dst_transform, width, height = rasterio.warp.calculate_default_transform(
src_crs=src_crs,
dst_crs=dst_crs,
width=width, height=height,
resolution=resolution,
**bounds)
data_resampled = np.full((nbands, height, width), DST_NODATA, data.dtype)
rasterio.warp.reproject(
source=data,
destination=data_resampled,
src_transform=transform,
src_crs=src_crs,
dst_transform=dst_transform,
dst_crs=src_crs,
resampling=resampling)
data = data_resampled
transform = dst_transform
profile = dict(
height=height,
width=width,
transform=transform,
crs=dst_crs,
driver='GTiff',
dtype=data.dtype,
count=nabnds)
with rasterio.open(outfile, 'w', **profile) as dst:
for i in range(nbands):
dst.write_band(i+1, data[i])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment