[gdal-dev] GDAL CLI converting to output datatype before performing calculation

Henry Walshaw henry at floodmapp.com
Wed Nov 12 21:49:31 PST 2025


Hi all,

In the docs for gdal raster calc (https://gdal.org/en/stable/programs/gdal_raster_calc.html#cmdoption-calc<https://_>) it states

Input rasters will be converted to 64-bit floating point numbers before performing calculations.

However I’ve found that when using an integer output datatype the base data is rounded to an integer before performing the calculation. e.g. converting a flood depth input.tif raster to a simple water / no water footprint:


gdal raster calc -i "A=depth.tif" -o footprint_b.tif --calc "A > 0 ? 1 : 0" --nodata none --ot Byte


The expected result for a value of (say) 0.1 is 1, but in the above calculation it comes out as 0. Obviously I can leave the output datatype alone so it stays the same as the input’s 64-bit float, but it seems unnecessary. Am I looking at a bug, or is this expected behaviour?

Regards,

Henry

​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20251113/205142ac/attachment-0001.htm>


More information about the gdal-dev mailing list