The following code only outputs integer even though set to float32.

'gdal_calc.py -A input_raster.tif --A_band 1 --outfile output_raster.tif --calc "0.005 * A.astype(float)" --NoDataValue -32767 --type Float32'

The input_raster.tif is Float32.

I have followed all the solutions here but it is not working.

  • 1
    Do you remove the existing output_raster.tif before running? Have you tried --NoDataValue -32767.0, I know it shouldn't make a difference as you're implicitly specifying --type Float32. What version of GDAL are you using (GDALINFO --VERSION)? – Michael Stimson Jan 24 '19 at 4:57
  • @Luke, I couldn't generate stat as I deleted all the files. – wondim Jan 24 '19 at 6:53
  • @MichaelStimson the cause of the problem could be existing input file. So what I was doing was calculate using input_raster. output_raster already exists but I though it will be overwritten most likely it is not. Could you answer it please. Your idea helped me! – wondim Jan 24 '19 at 6:54

From the sounds of it you were retaining the existing output file expecting it to be overwritten with a new file created using the -type Float32 parameter but the tool has not recreated the file, which is Int16, as Float32 but simply reused the existing raster completely ignoring all the creation options.

This may be intentional, like in GDAL_Rasterize, to force a particular datatype or may be a quirk of your particular GDAL version or even a partially locked file (unable to delete but write access can be granted).

| improve this answer | |
  • 2
    +1 Confirmed - gdal_calc.py will write into an existing file if -overwrite is not set. However, if the -overwrite option is set, the existing file is deleted and a new one created - source. – user2856 Jan 24 '19 at 11:16
  • @Luke I didn't know about it. Is this option there in gdalwrapand gdal_translate too? – wondim Jan 24 '19 at 14:59
  • 2
    @wondim - gdal_translate no, it will overwrite by default, gdalwarp has a -overwrite option as it supports writing/appending/mosaicing into an existing file and will behave the same as gdal_calc.py. – user2856 Jan 24 '19 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.