5

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

HDunn
  • 8,626
  • 3
  • 40
  • 71

1 Answers1

5

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'
radouxju
  • 49,636
  • 2
  • 71
  • 144