[gdal-dev] gdal_translate vs gdalwarp aggregation behaviour

John Baumgartner johnbaums at gmail.com
Mon Aug 26 10:16:14 PDT 2019


Hi all

I'm a bit confused by the difference in resampling behaviour seen when
using gdal_translate vs gdalwarp, when faced with ncol or nrow that is not
divisible by the aggregation factor.

For example, consider this 9 cell raster (attached, hopefully) with values
1 through 9, with resolution 1x1:

1 2 3
4 5 6
7 8 9

"gdalwarp in.tif out.tif -r average -tr 2 2"  gives cell values 3.0, 4.5,
7.5, 9.0, while "gdal_translate in.tif out.tif -r average -tr 2 2" gives 3,
4, 6, 7.

It seems that gdal_translate reuses cells in the calculation (i.e. reuses
the middle row and middle column, calculating averages of 1,2,4,5 then
2,3,5,6 then 4,5,7,8 then 5,6,8,9). In contrast, gdalwarp calculates
averages of 1,2,4,5 then 3,6 then 7,8 then 9 (i.e. dividing the raster into
tr x tr blocks where possible, and using fewer data where necessary along
right & bottom edges.

Things get weirder in some cases. For this 2x5 raster:

01 02 03 04 05
06 07 08 09 10

gdal_translate gives 4, 5.5, 7, seemingly calculating averages of 1,2,6,7
then 3,8 then 4,5,9,10.

And for this 2x7 raster:

01 02 03 04 05 06 07
08 09 10 11 12 13 14

gdal_translate gives 5.0, 6.5, 8.5, 10.0. Maybe I'm misreading things, but
is it calculating averages of 1,2,8,9 then 3,10 then 5,12 and then
6,7,13,14... and ignoring 4,11?

Is this behaviour documented anywhere? Can it be easily controlled? I guess
an option is to pad the raster with nodata first - can this be done within
the same gdal_translate call?

Cheers
John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20190827/8948ba39/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.tif
Type: image/tiff
Size: 591 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20190827/8948ba39/attachment.tif>


More information about the gdal-dev mailing list