I want to downsample a raster image using the max method that is available in GDAL in python.

In other words I would like to recreate the following bash command in python code:

gdalwarp -tr 32 32 -r max input_image.tif resampled_image.tif

I have found the following solution but for some reason this changes the values in the image to a range between approximately 0 and 2 when I load the created tif file.

How can I resample a raster image in python using the max method?

1 Answer 1


You are probably passing other resampling algorithm than max when using the solution you linked. The code should look like:

from osgeo import gdal

gdal.Warp('resampled_image.tif', 'input_image.tif', xRes=32 yRes=32, resampleAlg=gdal.GRA_Max)

Another alternative is calling the command from Python using the subprocess module:

import subprocess

subprocess.run('gdalwarp -tr 32 32 -r max input_image.tif resampled_image.tif')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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