1

I want to create mbtiles with the GDAL Python API. How can I integrate format specific options like "TILE_FORMAT = 'jpeg', QUALITY='90'" for mbtiles?

from osgeo import gdal

path = r'C:\Users\go\my.vrt'
pathout = r'C:\Users\go\my.mbtiles'
src_ds = gdal.Open(path)
ds = gdal.Translate(pathout , src_ds, format = 'mbtiles')
ds = No
2
  • You can pass them as parameter(s). See gis.stackexchange.com/questions/352643/… for some example. Aug 19 '20 at 12:07
  • that's do not work in my test. Because thats mbtiles specific options and not gdal.translate options that i want to add. i tested it with: ds = gdal.Translate(pathout , src_ds, format = 'mbtiles', TILE_FORMAT = 'jpeg', QUALITY='90')
    – David
    Aug 19 '20 at 12:21
2

Those are Creation Options. You can pass Creation Options to gdal.Translate using the creationOptions parameter. The names are the same as for the gdal.TranslateOptions function: https://gdal.org/python/osgeo.gdal-module.html#TranslateOptions

They are to be key=value pairs as strings in a list.

For your example:

creation_options = ["TILE_FORMAT=JPEG", "QUALITY=90"]

ds = gdal.Translate(
    pathout, src_ds, 
    format='mbtiles', creationOptions=creation_options
)
2
  • 1
    Thats it, but one little misstake: creationOptions = creation_options. Thanks!
    – David
    Aug 19 '20 at 14:18
  • Thaanks, fixed! Aug 19 '20 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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