resample rasterio python

Solutions on MaxInterview for resample rasterio python by the best coders in the world

showing results for - "resample rasterio python"
Loris
24 Oct 2019
1import rasterio
2from rasterio.enums import Resampling
3
4upscale_factor = 2
5
6with rasterio.open('my_raster.tif') as dataset:
7
8    # resample data to target shape
9    data_s = dataset.read(
10        out_shape=(
11            dataset.count,
12            int(dataset.width * upscale_factor),
13            int(dataset.height * upscale_factor)
14        ),
15        resampling=Resampling.bilinear
16    )
17
18    # scale image transform
19    transform = dataset.transform * dataset.transform.scale(
20        (dataset.width / data.shape[-2]),
21        (dataset.height / data.shape[-1])
22    )