importToMbtiles
import sqlite3, sys, logging, time, os, json, zlib, re
'''
MapDBImporter-latest -f png -mName "World Light" -mDescription "A simple, light grey world map" -s "F:\google\map\zoom" -d "F:\google\map\mbtiles.sqlite"
'''
#mbtiles_file = r"F:\\google\\map\\mbtiles.sqlite"
mbtiles_file = r"D:\\mbtiles.sqlite"
conn = sqlite3.connect(mbtiles_file)
cur = conn.cursor()
'''
cur.execute("create table tiles ( zoom_level integer, tile_column integer, tile_row integer, tile_data blob); ")
cur.execute("create table metadata(name text, value text);")
cur.execute("CREATE TABLE grids (zoom_level integer, tile_column integer, tile_row integer, grid blob);")
cur.execute("CREATE TABLE grid_data (zoom_level integer, tile_column integer, tile_row integer, key_name text, key_json text);")
cur.execute("create unique index name on metadata (name);")
cur.execute("create unique index tile_index on tiles(zoom_level, tile_column, tile_row);")
'''
'''
name = "format"
value = "png"
cur.execute('insert into metadata (name, value) values (?, ?)', (name, value))
name = "name"
value = "world"
cur.execute('insert into metadata (name, value) values (?, ?)', (name, value))
name = "description"
value = "Metadata Information"
cur.execute('insert into metadata (name, value) values (?, ?)', (name, value))
name = "version"
value = "3"
cur.execute('insert into metadata (name, value) values (?, ?)', (name, value))
conn.commit()
#
'''
#cur.execute('delete from tiles')
def getDirs(path):
return [name for name in os.listdir(path) if os.path.isdir(os.path.join(path, name))]
directory_path = r"E:\\google\\en\\map"
count = 0
for zoomDir in getDirs(directory_path):
print("start level: " + zoomDir)
z = int(zoomDir)
for columnDir in getDirs(os.path.join(directory_path, zoomDir)):
x = int(columnDir)
for current_file in os.listdir(os.path.join(directory_path, zoomDir, columnDir)):
file_name, ext = current_file.split('.', 1)
y = int(file_name)
f = open(os.path.join(directory_path, zoomDir, columnDir, current_file), 'rb')
file_content = f.read()
f.close()
#
cur.execute("insert into tiles (zoom_level, tile_column, tile_row, tile_data) values(?, ?, ?, ?);", (z, x, y, sqlite3.Binary(file_content)))
count = count + 1
if count > 1500:
count = 0
conn.commit()
conn.commit()
conn.commit()
print("finish level: " + zoomDir)
conn.commit()
conn.commit()
conn.close()