0

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.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked May 3, 2020 at 17:12

1 Answer 1

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
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.