4

I have lots of 16bit 3-band .tif from one sattelite. In batch processing i've made them 8-bit 4-band (RGBA) with LZW compression (.tif). Now i'm trying using gdal_translate (gdal 2.1 from QGIS 2.16) generate .mbtiles. But some of the output mbtiles have black and white background although, original raster has alpha channel. Format of mbtiles is png.after gdal_translatefigure1

I've also tried gdal2tiles.py and mb-util utilities. they made good mbtile from point of transparency but all the pngs are turned upside down see figure2 (gdalinfo shows that origin has wrong Y coordinate with "-")enter image description here figure2

gdal_translate with option -a_ullr 0 0 256 256 didn't help me to turn pngs. gdalwarp -to SRC_METHOD=NOGEOTRANSFORM helped to turn pngs, but after mb-util the mbtile became the same as figure1 (without alpha)

After that i've tried global mapper trial and it make normal mbtiles as i want to do (see figure 3).enter image description here figure3

I've noticed 2 things:

  1. Global Mapper makes all the tiles 32bit. I mean if it is not border tile it anyway has 4 band (32bit). after gdal_translate and mb-util non-border tiles (which are tottaly covered by color pixels) tiles have 3 band (24 bit).
  2. the blank tiles for good rasters (for which output mbtiles has trancparency) have size of 872 bytes and for bad rasters size of 871 bytes.

p.s. The blue background - it is QGIS background to clearly see backgrounds of raster. please do not offer nodata because this makes holes in the bright places in raster like roofs etc.

1 Answer 1

1

For the issue "turned pngs", you may be able to use https://github.com/roblabs/gdal2tilesp

which has support for xyz, from the notes: Generates Leaflet layer for use with the XYZ default format. Where the tms parameter is set to false

I've also tried gdal2tiles.py and mb-util utilities. they made good mbtile from point of transparency but all the pngs are turned upside down see figure2 (gdalinfo shows that origin has wrong Y coordinate with "-")


python gdal2tilesp.py -h

-o OUTPUT_CACHE, --output=OUTPUT_CACHE
                    Format for output cache. Values allowed are tms and
                    xyz, being xyz the default value
4
  • 1
    Great job!! excellent improvement!! Thank you for answer, everything worked. I've edited some lines: I changed tileSize from 512 to 256. In worker_base_tiles i removed zoom_limits.put(gdal2tiles.tminz) and tmaxz, because in main at 2601 line queue became empty and thrown me an error. I've changed tminz\tmaxz = gdal2tiles.tminz\tmaxz. i didn't find reason to use put method, because in main you initiate GDAL2Tiles class which has tminz and tmaxz parameters. Aug 18, 2016 at 8:52
  • Dmitriy Litvinov — great to hear. Would you mind sharing your changes in Github? This code came from many others. That way we can improve that tool for others. I've opened up this issue which you can submit a PR for — github.com/roblabs/gdal2tilesp/issues/1
    – RobLabs
    Aug 18, 2016 at 15:00
  • I should also note that gdal.org/gdal2tiles.html also accepts the parameter for --output, but it does not explain that when you use -h. The source has the option, but the help file does not show that.
    – RobLabs
    Aug 18, 2016 at 15:28
  • You might also try the new COG driver -of COG which should create an alpha band by default. If not create a mosaic from the color bands you want -b 1 -b 2 -b 3 for example, then -addalpha. Then create your COG from the mosaic. It all depends on how gdal interprets the original alpha band, but I have found it best to create the alpha band with gdal tools. You can then create your mbtiles with gdal_translate and gdaladdo for the overviews.
    – malcolm
    Sep 23, 2021 at 18:42

Your Answer

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

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