[GIS] gdal_translate not using correct types when resampling

gdalgdal-translategdalwarp

I'm using gdal_translate to downsample some data using averaging. The input data uses an Int data type, and I want to store the float values of the pixel averaging.

However, even when I force gdal_translate to use Float32, the values in the output file have been cast to int. The command I'm using is:

gdal_translate -tr 0.0075 0.0075 -r average -ot Float32 -co COMPRESS=LZW -q in.tif out.tif

When I use the same options for gdalwarp, I get the expected result (float values).

gdalwarp -tr 0.0075 0.0075 -r average -ot Float32 -co COMPRESS=LZW -q in.tif out.tif

Am I missing something, or is this a bug in gdal_translate?

Best Answer

I understand this is a bit hard to understand, but this is an expected result given the design of both utilities. In gdal_translate, the resampling is done with the input datatype (so Int), the conversion to the output data type is done late in the process. In gdalwarp, -ot Float32 implies a -wt Float32 (working datatype), hence more expected results.