Is there any way to reduce a gdal raster in Python by sampling e.g. every 5th cell in both longitude and latitude directions?
The methods supported by gdal (e.g. gdalwarp, Rescale raster to custom resolution using sum as the function to aggregate) don't appear to support this.
asked May 3, 2020 at 17:12
1 Answer 1
Rasterio can do this: https://rasterio.readthedocs.io/en/latest/topics/resampling.html#up-and-downsampling
Code copied from link:
import rasterio
from rasterio.enums import Resampling
upscale_factor = 1/5
with rasterio.open("example.tif") as dataset:
# resample data to target shape
data = dataset.read(
out_shape=(
dataset.count,
int(dataset.height * upscale_factor),
int(dataset.width * upscale_factor)
),
resampling=Resampling.bilinear
)
# scale image transform
transform = dataset.transform * dataset.transform.scale(
(dataset.width / data.shape[-1]),
(dataset.height / data.shape[-2])
)
answered May 3, 2020 at 17:55
lang-py