Last active
September 18, 2020 02:43
-
-
Save prakharcode/24fbb243fe06c842b51b1bc14d58d99f to your computer and use it in GitHub Desktop.
Resample using rasterio
This file contains hidden or 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
import rasterio | |
from rasterio import Affine | |
from rasterio.warp import reproject, Resampling | |
with rasterio.open('path/to/band') as src: | |
scale = 2 # scaling amount of data so a scale of 2 would double the pixel size | |
aff = src.transform | |
# adjust the new affine transform to new scale | |
newaff = Affine(aff.a / scale, aff.b, aff.c, | |
aff.d, aff.e / scale, aff.f) | |
meta = src.profile | |
meta.update(affine = newaff) | |
with rasterio.open('path/to/output/destination', 'w', **meta) as dst: | |
reproject(source=rasterio.band(src, 1), | |
destination=rasterio.band(dst, 1), | |
resampling = Resampling.bilinear) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment