[gdal-dev] Downsampling with gdalwarp

Frank Warmerdam warmerdam at pobox.com
Tue Jul 29 14:54:19 EDT 2008


Stanley Glidden wrote:
> Hi,
> 
> Can someone tell me if anything has changed in terms of being able to
> downsample using averaging with gdalwarp. I found a post from a few years
> back that said the only way to accomplish this is through an option in the
> virtual file driver. Is this still the case? If so what is the syntax to 
> downsample
> with the virtual file driver?

Stanley,

I'm not exactly sure how averaging would be accomplished with the
VRT driver, though I think it would be possible.

However, I recently (in trunk) exposed the overview generation function
for direct use from the swig bindings.  This means that generating an
average downsampled image could be accomplished like this in python:

import gdal

srcfile = gdal.Open('utm.tif')

dstfile1 = gdal.GetDriverByName('GTiff').Create('avg1.tif', 200, 100, 1,
                                                gdal.GDT_Byte )
dstfile2 = gdal.GetDriverByName('GTiff').Create('avg2.tif', 100, 50, 1,
                                                gdal.GDT_Byte )

gdal.RegenerateOverview( srcfile.GetRasterBand(1),
                          [dstfile1.GetRasterBand(1),
                           dstfile2.GetRasterBand(1)],
                          'average' )

Perhaps that would be the easiest approach.

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org



More information about the gdal-dev mailing list