[gdal-dev] help with resampling via python
Klokan Petr Přidal
klokan at klokan.cz
Wed Apr 1 07:57:26 EDT 2009
Hi Chris,
You have two options in GDAL API for resampling via Python:
gdal.RegenerateOverview() with 'average' and 'mode' algorithms.
and
gdal.ReprojectImage() with 'bilinear','cubic','cubicspline' and
'lanczos' algorithms.
Example of such functionality is in gdal2tiles.py in function
GDAL2Tiles.scale_query_to_tile():
http://code.google.com/p/maptiler/source/browse/trunk/maptiler/gdal2tiles.py#1433
I am resampling in memory (because I am working only with small tiles
with usual size 256x256px):
mem_drv = gdal.GetDriverByName( 'MEM' )
target = mem_drv.Create('', outputXsize, outputYsize, bands)
I think gdal.ReprojectImage() would be able to rescale also into VRT dataset.
Another choice is to create copy into the VRT dataset and change the
target raster size in XML attributes manually in the text.
In that case the average algorithm in VRT is exposed by the
<AveragedSource> tag...
Best,
Klokan
2009/4/1 Chris Somerlot <csomerlot at gmail.com>:
> Having trouble figuring out how to resample an image to a different cell
> size from python. I looked over the VRT driver page and have been trying to
> get this to work:
>
> from osgeo import gdal
>
> gdal.AllRegister()
>
> src = gdal.Open('DOQ_test.TIF')
> drv = gdal.GetDriverByName('VRT')
> dst = drv.CreateCopy("", src, 0)
>
> dst.RasterXSize = '125'
>
> But it seems the cell size in the datasets and the bands are read only? Is
> there any programmatic way to do this?
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>
--
http://blog.klokan.cz/
http://www.maptiler.org/
http://www.oldmapsonline.org/
More information about the gdal-dev
mailing list