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

Vince
  • 20,017
  • 15
  • 45
  • 64
David
  • 61
  • 4
  • You can pass them as parameter(s). See https://gis.stackexchange.com/questions/352643/gdal-translate-in-python-where-do-i-find-how-to-convert-the-command-line-argum/352647#352647 for some example. – bugmenot123 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

1 Answers1

3

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 )

bugmenot123
  • 11,011
  • 3
  • 34
  • 69