[GIS] Conditional statement in gdal_calc with result as float, not boolean

gdalgdal-calcqgis-2qgis-processingraster-calculator

Many examples on gis.se that refer to gdal_calc give a boolean example.
example 1
example 2

If I need to calculate a conditional statement on a float:

If Raster_Value >= 1024, then 1024; else Raster_Value.

How do I perform that operation in the gdal raster calculator command line

EDIT
I tried radouxju answer and it worked, except for the cell values that didn't.
here are 3 kinds of results I got

enter image description here

Here is the tool gui and the parameters I've entered
enter image description here

Best Answer

you can define the output type using the "type" option

--type=TYPE output datatype, must be one of ['Int32', 'Int16', 'Float64', 'UInt16', 'Byte', 'UInt32', 'Float32']

so it would look like this

gdal_calc.py -A yourInput.tif --outfile=yourOutput.tif --calc="1024*(A>=1024)+A*(A<1024)" --NoDataValue=0 --type='Float32'
Related Question