Created
October 5, 2017 12:21
-
-
Save j08lue/00e3a1bf6b648fe19900159631fd946a to your computer and use it in GitHub Desktop.
rasterio reproject array to array and write to disk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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