[gdal-dev] Fwd: Creating MBTiles with transparent background from GeoTIFF
Rahkonen Jukka
jukka.rahkonen at maanmittauslaitos.fi
Mon Jun 27 06:22:31 PDT 2022
Hi,
Your original image does not have nodata:
gdalinfo sample_geotiff.tif
...
Band 1 Block=8889x1 Type=Byte, ColorInterp=Red
Band 2 Block=8889x1 Type=Byte, ColorInterp=Green
Band 3 Block=8889x1 Type=Byte, ColorInterp=Blue
MBTiles driver does not support transparency with nodata but with alpha https://gdal.org/drivers/raster/mbtiles.html
One possible workflow:
Convert RGB 0 0 0 pixels into alpha with gdalwarp
gdalwarp -srcnodata 0 -dstalpha sample_geotiff.tif sample_with_alpha.tif
Convert this input with alpha into MBTiles
gdal_translate -tr 0.035 0.035 -of MBTILES sample_with_alpha.tif file1.mbtiles
I guess there are other ways to get a desired result, I stopped experimenting when this seemed to work.
-Jukka Rahkonen-
Lähettäjä: gdal-dev <gdal-dev-bounces at lists.osgeo.org> Puolesta Kanishk Varshney
Lähetetty: maanantai 27. kesäkuuta 2022 15.22
Vastaanottaja: gdal-dev at lists.osgeo.org
Aihe: [gdal-dev] Fwd: Creating MBTiles with transparent background from GeoTIFF
Hey all,
I am stuck with MBTiles creation from GeoTIFF files that have a black background (RGB: 0,0,0).
In QGIS, I am able to generate MBTiles via the following steps:
* Set Transparency pixel (0 0 0) to get a geotiff with transparent background
* Use Generate XYZ tiles (MBTiles) tool to generate the MBTiles for the above generated geotiff.
I want to automate the workflow using python, but not able to achieve great success.
The following commands are used:
gdal_translate -tr 0.035 0.035 -a_nodata none -of MBTILES file1.tif file1.mbtiles
gdaladdo -r nearest file1.mbtiles 2 4 8 16
This results in following issues:
1. The generated mbtiles don't have all the resolutions that manually generated MBTiles have
2. Background is still black, which is a big concern for my usecase
Any help or alternative would be appreciated. Attaching a sample Geotiff for reference
[https://ssl.gstatic.com/docs/doclist/images/icon_10_generic_list.png] sample_geotiff.tif<https://eur06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdrive.google.com%2Ffile%2Fd%2F1HJaw59FVEwG_9sEN8bvfeRw1GrawGnUb%2Fview%3Fusp%3Ddrive_web&data=05%7C01%7Cjukka.rahkonen%40maanmittauslaitos.fi%7Cf59902129f0d4022d41208da5837ad09%7Cc4f8a63255804a1c92371d5a571b71fa%7C0%7C1%7C637919293399292802%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000%7C%7C%7C&sdata=hmfLGGUvB05Rl34jbgA%2F6SiI%2BTdImGhVUK%2FEHxGV8d0%3D&reserved=0>
Thanks,
Kanishk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20220627/4363377f/attachment-0001.htm>
More information about the gdal-dev
mailing list