resample rasterio python code example
Example: resample rasterio python
import rasterio
from rasterio.enums import Resampling
upscale_factor = 2
with rasterio.open('my_raster.tif') as dataset:
# resample data to target shape
data_s = dataset.read(
out_shape=(
dataset.count,
int(dataset.width * upscale_factor),
int(dataset.height * upscale_factor)
),
resampling=Resampling.bilinear
)
# scale image transform
transform = dataset.transform * dataset.transform.scale(
(dataset.width / data.shape[-2]),
(dataset.height / data.shape[-1])
)