I am running the following code in order to resample a single-band TIFF file, whose data are going from 0 to 100 with 255 being the nodata value

"gdalwarp -t_srs "+srs+" -tr "+pxsz+" "+pxsz+" -te "+xmin+" "+ymin+" "+xmax+" "+ymax+" -te_srs "+srs+" -r average -srcnodata 255 -dstnodata -999 -ot Float32 -of GTiff "+fin+" "+fou

The problem is that the output file have a single alpha band instead of the grey original, as you can see by the gdalinfo

Band 1 Block=11x9 Type=Byte, ColorInterp=Alpha

while the original file had

Band 1 Block=4830x1 Type=Byte, ColorInterp=Gray

How can I solve this?

  • 2
    There is also another odd feature: you ask gdalwarp to create a Float32 image but gdalinfo is from an 8-bit image. Did file "fou" exist already?
    – user30184
    May 17, 2023 at 17:48
  • @user30184 fou is the output file which does not exist already. I am using Float32 in order to get the average values with comma. Does this create a problem?
    – Andrea
    May 18, 2023 at 8:24

1 Answer 1


I can't reproduce with source data that I created with gdal_create by the information that you have given.

gdal_create -of GTiff -outsize 2830 3000 -co blockxsize=2830 -co blockysize=1 -bands 1 -a_srs epsg:4326 -a_ullr 30 40 20 50 source.tif

gdalinfo source.tif
Band 1 Block=2830x1 Type=Byte, ColorInterp=Gray

Then I used your gdalwarp command in a bit simplified format

gdalwarp -r average -t_srs epsg:3857 -srcnodata 255 -dstnodata -999 -ot Float32 -of GTiff source.tif target.tif 

Gdalinfo reports the target band to present Gray, and the data type is Float32

gdalinfo target.tif

Band 1 Block=2375x1 Type=Float32, ColorInterp=Gray
  NoData Value=-999

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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