0

I have created 2 Mbtiles via QGIS: 1) one Mbtile is from zoom 0 until 10 & is a map of the whole world, 2) and another one from zoom 0 until 17 & is a detailed map of one country.

I would like to merge the two Mbtiles, and have the Mbtile of the detailed country overlapping the Mbtile of whole world. Also the merged result to be from zoom 0 til 17 (the whole world would disappear at zoom 10, but the country will remain until zoom 17).

What program/method should I use? Is it possible to merge them via QGIS?

2 Answers2

1

You can use tile-join, it has a bunch of flags so you can customize the output.

rubenpoppe
  • 307
  • 2
  • 10
0

I use Python to merge MBTiles files. Be sure to update the matadata table noting the min max zoom. They are just sqlite databases with a unique extension.

This example does not include data validation. I did not test this example -- as it is stripped down from where I batch process output from QGIS.

It is less problematic to use an IDE other than QGIS's python interface. Does not require anything specific to QGIS or PyQGIS.

import sqlite3 as sqlite

def processOneSource(srcDB, dstDB):
    # create_index_sql = "CREATE UNIQUE INDEX tile_index on tiles (zoom_level, tile_column, tile_row);"
    # dstDB.connection.execute(create_index_sql)
    # the index forces an error if there is already a tile for the same zxy

    sqlite_insert_blob_query = """ INSERT INTO tiles (zoom_level, tile_column, tile_row, tile_data) VALUES (?, ?, ?, ?)"""

    tiles = srcDB.connection.execute('select zoom_level, tile_column, tile_row, tile_data from tiles;')

    for t in tiles:
        z = t[0]
        x = t[1]
        y = t[2]
        data = t[3]

        # example of how you might include exclude tiles
        if not (z == 12 or z == 13 or z == 14 or z == 15 or z == 16):
            continue

        print(str((t[0], t[1], t[2])))

        data_tuple = (t[0], t[1], t[2], t[3])
        try:
            dstDB.connection.execute(sqlite_insert_blob_query, data_tuple)
        except Exception as e:
            print(e)

    dstDB.commit()


if __name__ == '__main__':
    srcDB = sqlite.connect("path_to_yourfilename")
    dstDB = sqlite.connect("path_to_yourfilename")
    processOneSource(srcDB, dstDB)