1

I have this GeoTIFF generated through UAV mapping. It has 4 bands: red, green, blue and alpha. I've been trying to use gdal2tiles to use this geotiff as a basemap on a Leaflet project.

The thing is I cant get the alpha band to be transparent on Leaflet as it is on QGIS.

This is how it looks on QGIS This is how it looks on QGIS

And this it how it looks on Leaflet And this is how it looks on leaflet

Here we have the raster info:

Driver: GTiff/GeoTIFF
Files: input.tif
Size is 64957, 74080
Coordinate System is:
GEOGCRS["WGS 84",
    DATUM["World Geodetic System 1984",
        ELLIPSOID["WGS 84",6378137,298.25722356049,
            LENGTHUNIT["metre",1]]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["degree",0.0174532925199433]],
    CS[ellipsoidal,2],
        AXIS["geodetic latitude (Lat)",north,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433]],
        AXIS["geodetic longitude (Lon)",east,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433]],
    ID["EPSG",4326]]
Data axis to CRS axis mapping: 2,1
Origin = (-51.468682631840061,-21.737483235282060)
Pixel Size = (0.000000603929836,-0.000000603929836)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  ( -51.4686826, -21.7374832) ( 51d28' 7.26"W, 21d44'14.94"S)
Lower Left  ( -51.4686826, -21.7822224) ( 51d28' 7.26"W, 21d46'56.00"S)
Upper Right ( -51.4294532, -21.7374832) ( 51d25'46.03"W, 21d44'14.94"S)
Lower Right ( -51.4294532, -21.7822224) ( 51d25'46.03"W, 21d46'56.00"S)
Center      ( -51.4490679, -21.7598528) ( 51d26'56.64"W, 21d45'35.47"S)
Band 1 Block=64957x1 Type=Byte, ColorInterp=Red
  Minimum=1.000, Maximum=255.000, Mean=171.735, StdDev=87.606
  NoData Value=0
  Metadata:
    STATISTICS_MAXIMUM=255
    STATISTICS_MEAN=171.73513846298
    STATISTICS_MINIMUM=1
    STATISTICS_STDDEV=87.605566410796
    STATISTICS_VALID_PERCENT=99.98
Band 2 Block=64957x1 Type=Byte, ColorInterp=Green
  Minimum=1.000, Maximum=255.000, Mean=169.218, StdDev=88.007
  NoData Value=0
  Metadata:
    STATISTICS_MAXIMUM=255
    STATISTICS_MEAN=169.21831334207
    STATISTICS_MINIMUM=1
    STATISTICS_STDDEV=88.007452394777
    STATISTICS_VALID_PERCENT=99.98
Band 3 Block=64957x1 Type=Byte, ColorInterp=Blue
  Minimum=1.000, Maximum=255.000, Mean=156.433, StdDev=96.602
  NoData Value=0
  Metadata:
    STATISTICS_MAXIMUM=255
    STATISTICS_MEAN=156.43343641947
    STATISTICS_MINIMUM=1
    STATISTICS_STDDEV=96.601623969202
    STATISTICS_VALID_PERCENT=99.91
Band 4 Block=64957x1 Type=Byte, ColorInterp=Alpha
  Minimum=255.000, Maximum=255.000, Mean=255.000, StdDev=0.000
  NoData Value=0
  Metadata:
    STATISTICS_MAXIMUM=255
    STATISTICS_MEAN=255
    STATISTICS_MINIMUM=255
    STATISTICS_STDDEV=0
    STATISTICS_VALID_PERCENT=53.82

I've used the following parameters:

python3 -m gdal2tiles -p mercator -z 15-22 -w all -r average -a 255.0 input.tif output_folder

Do you have any hints on what am I missing?

1

1 Answer 1

2

I found a way to fix it.

I ran the unique values algo and discovered the alpha band had two unique values (0 and 255). I found it easier to just remove the alpha band through gdal_translate.

Then I took a look at the brand new 3-banded geotiff's histogram and noticed the nodata value was 255. Finally, I tried gdal2tiles again (with -a 255) and it worked.

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.