Search code examples
pythongdal

How can I change the resolution of a raster using GDAL?


I am looking for the best way to change the resolution of a GDAL raster dataset.

For example, I have a raster that has a pixel size of (30, -30), and I would like to change the pixel size to (5, -5), interpolating all values for a given pixel into the output raster.

So for each pixel of the input raster, I would like to have 36 pixels in the output raster that all share the same value.

If I run gdalwarp -tr 5 -5 inputRaster.tif outputRaster.tif, I get exactly the result that I'm looking for, and so I would assume that I should be able to replicate this functionality with some GDAL function.

I would prefer to avoid using a call to python's Subprocess class, if possible.


Solution

  • You need to reproject the raster. For example, from an interactive Python shell:

    from osgeo import gdal
    help(gdal.ReprojectImage)
    

    A Python example is provided in the test suite.

    More complete documentation is provided for the C++ function GDALReprojectImage.