[gdal-dev] gdal_calc.py floating point arithmetic

Antonio Falciano afalciano at yahoo.it
Fri Jul 15 00:48:12 PDT 2016

Il 15/07/2016 02:13, Sam Wilson ha scritto:
> Hi,
> I’m attempting to linearly interpolate two geotiff files using gdal_calc.py.  The geotiff files are 3 hours apart, so for example hour 0 and hour 3.  I’d like to end up with hourly data, so I need hours 1 and 2.
> Below are the commands I’m using:
> gdal_calc.py -A hour0.tif -B hour3.tif —outfile=hour1.tif —calc=“(A+B)*0.333”
> gdal_calc.py -A hour0.tif -B hour3.tif —outfile=hour2.tif —calc=“(A+B)*0.667”
> However, hour1.tif and hour2.tif appear to be the exact same.
> Does gdal_calc.py not allow using floating point values in the calculation? Or, am I doing something else wrong?

Hi Sam,
if your input data are both of type Int*, you should force the output 
gdal_calc.py -A hour0.tif -B hour3.tif --outfile=hour1.tif 
--calc="(A+B)*0.333" --type Float32
gdal_calc.py -A hour0.tif -B hour3.tif --outfile=hour2.tif 
--calc="(A+B)*0.667" --type Float32
Hope this helps.


Antonio Falciano

More information about the gdal-dev mailing list