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, this question) don't obviously support this. Is anyone aware of a method?

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(
            int(dataset.height * upscale_factor),
            int(dataset.width * upscale_factor)

    # scale image transform
    transform = dataset.transform * dataset.transform.scale(
        (dataset.width / data.shape[-1]),
        (dataset.height / data.shape[-2])
  • Oooh awesome, thanks snowman :)
    – geotheory
    May 3, 2020 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.