Saturday, 11 April 2015

gdal - How to add alpha chanel to mbtiles in gdal_translate?


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.



Answer



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

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...