8

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.

James
  • 1,485
  • 2
  • 16
  • 21

2 Answers2

6

Use gdal.Warp function:

gdal.Warp('outputRaster.tif', 'inputRaster.tif', xRes=5, yRes=5)
Ivan Kovtun
  • 645
  • 1
  • 11
  • 18
6

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.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Mike T
  • 41,085
  • 18
  • 152
  • 203