[GIS] Converting a 32-bit GeoTIFF to map tiles using gdal2tiles

gdalgdal2tilesgeotiff-tiff

I have a 32-bit GeoTIFF file I'm trying to convert to map tiles using gdal2tiles.py.

What the GeoTIFF is supposed to look like when loaded straight into QGIS (no scaling, styling, etc):

enter image description here

And here is the output of gdalinfo input.tif:

bash-3.2$ gdalinfo input.tif
Driver: GTiff/GeoTIFF
Files: input.tif
       input.tif.aux.xml
Size is 294, 192
Coordinate System is:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0],
    UNIT["degree",0.0174532925199433],
    AUTHORITY["EPSG","4326"]]
Origin = (-83.400000000000006,35.200000000000003)
Pixel Size = (0.016666666666667,-0.016666666666667)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  COMPRESSION=LZW
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  ( -83.4000000,  35.2000000) ( 83d24' 0.00"W, 35d12' 0.00"N)
Lower Left  ( -83.4000000,  32.0000000) ( 83d24' 0.00"W, 32d 0' 0.00"N)
Upper Right ( -78.5000000,  35.2000000) ( 78d30' 0.00"W, 35d12' 0.00"N)
Lower Right ( -78.5000000,  32.0000000) ( 78d30' 0.00"W, 32d 0' 0.00"N)
Center      ( -80.9500000,  33.6000000) ( 80d57' 0.00"W, 33d36' 0.00"N)
Band 1 Block=294x3 Type=Float64, ColorInterp=Gray
  Min=0.005 Max=0.759 
  Minimum=0.005, Maximum=0.759, Mean=0.057, StdDev=0.076
  NoData Value=-1.69999999999999994e+308
  Metadata:
    STATISTICS_MAXIMUM=0.75856912136078
    STATISTICS_MEAN=0.057134358222004
    STATISTICS_MINIMUM=0.0052262963727117
    STATISTICS_STDDEV=0.075826669687323

What a sample tile looks like when converted using gdal2tiles.py input.tif:

enter image description here

OK, so clearly there's something going on with floating points and possibly number signing. So I try to convert it:

gdal_translate input.tif output.tif -ot UInt16

… And then convert to tiles:

Result: Only values over 0.5 carry over as black. Everything else is white.
enter image description here

I feel like there is something obvious that I'm missing. Does anyone have any insights into what's going on here?

Things I've done:

-Try all the different convert options:

Byte: Monochrome conversion

Int16: All black

UInt16: Monochrome conversion

UInt32: Monochrome conversion

Int32: All black

Float32: TV snow noise

Float64: TV snow noise

CInt16: All black

CInt32: All black

CFloat32: TV snow noise

CFloat64: TV snow noise

Best Answer

My guess is that you have a far out of range nodata value, like -9999, which is not set as the nodata value in the .tif. Then, when gdal_translate rescales your values from whatever into 0 to 255, you get one bin with the nodata at 0 and one bin with everything else at 255. So, you need to check what value your nodata pixels have and then set the nodata value in your .tif using gdal_edit -a_nodata -9999 or similar.