[英]How can I merge two Mbtiles?
我通過 QGIS 創建了 2 個 Mbtiles:1) 一個 Mbtile 是從 0 到 10 縮放並且是整個世界的地圖,2) 另一個是從 0 到 17 縮放並且是一個國家的詳細地圖。
我想合並這兩個 Mbtiles,並讓詳細國家/地區的 Mbtile 與整個世界的 Mbtile 重疊。 合並的結果也是從縮放 0 到 17(整個世界將在縮放 10 時消失,但國家將保留到縮放 17)。
我應該使用什么程序/方法? 是否可以通過 QGIS 合並它們?
我使用 Python 來合並 MBTiles 文件。 請務必更新 matadata 表,注意最小最大縮放。 它們只是具有獨特擴展名的 sqlite 數據庫。
此示例不包括數據驗證。 我沒有測試這個例子——因為它是從我批處理 QGIS 輸出的地方刪除的。
使用 QGIS 的 python 接口以外的 IDE 問題較小。 不需要任何特定於 QGIS 或 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)
您可以使用tile-join ,它有一堆標志,因此您可以自定義輸出。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.