TransWikia.com

Use GDAL Python API to generate mbtiles

Geographic Information Systems Asked on October 26, 2020

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:Usersgomy.vrt'
pathout = r'C:Usersgomy.mbtiles'
src_ds = gdal.Open(path)
ds = gdal.Translate(pathout , src_ds, format = 'mbtiles')
ds = No

One Answer

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
)

Correct answer by bugmenot123 on October 26, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP