Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

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.

like image 226
James Avatar asked Oct 10 '11 23:10

James


2 Answers

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.

like image 100
Mike T Avatar answered Sep 21 '22 06:09

Mike T


Use gdal.Warp function:

gdal.Warp('outputRaster.tif', 'inputRaster.tif', xRes=5, yRes=5)
like image 32
Ivan Kovtun Avatar answered Sep 20 '22 06:09

Ivan Kovtun