1
0
mirror of https://github.com/alfanhui/mbtilesToPngs.git synced 2025-05-31 14:20:13 -07:00

Added print out for pubspec flutter, also added -tsm option to fix y coordinates from tms to zxy format. See https://alastaira.wordpress.com/2011/07/06/converting-tms-tile-coordinates-to-googlebingosm-tile-coordinates/

This commit is contained in:
Alfanhui 2018-06-07 13:43:17 +01:00
parent 9c5b09214a
commit 3939ce97a5

View File

@ -23,26 +23,42 @@ def create_connection(db_file):
return None return None
def select_all_images(conn): def select_all_images(conn, tms):
""" """
Query all rows in the tasks table Query all rows in the tasks table
:param conn: the Connection object :param conn: the Connection object
:return: :return:
""" """
cur = conn.cursor() cur = conn.cursor()
cur.execute("SELECT * FROM images") cur.execute("SELECT * FROM images")
rows = cur.fetchall() rows = cur.fetchall()
assets = {}
print("Image count: " + str(len(rows))) print("Imamge count: " + str(len(rows)))
print("TMS: " + str(tms))
for row in rows: for row in rows:
result = get_Metadata(conn, row[1]) result = get_Metadata(conn, row[1])
# for printing
dir = str(result['zoom']) + "/" + str(result['column'])
assets[dir] = dir
# tsm check
xValue = result['row']
if(tms):
ymax = 1 << result['zoom']
xValue = ymax - result['row'] - 1
# generate png
blobToFile( blobToFile(
result['zoom'], str(result['zoom']), # {z}
result['column'], str(result['column']), # {x}
result['row'], str(xValue), # {y}
row[0], row[0], # data
) )
for asset in assets:
print ('- assets/map/' + assets[asset] + "/")
def get_Metadata(conn, id): def get_Metadata(conn, id):
@ -55,7 +71,7 @@ def get_Metadata(conn, id):
cur.execute("SELECT * FROM map WHERE tile_id = ?", [id]) cur.execute("SELECT * FROM map WHERE tile_id = ?", [id])
row = cur.fetchone() row = cur.fetchone()
return({'zoom': str(row[0]), 'column': str(row[1]), 'row': str(row[2])}) return({'zoom': row[0], 'column': row[1], 'row': row[2]})
def mkdir_p(path): def mkdir_p(path):
@ -76,20 +92,21 @@ def blobToFile(dir0, dir1, dir2, ablob):
output_file.write(ablob) output_file.write(ablob)
def beginConvertion(database): def beginConvertion(database, tms):
#database = "./OSMBright.mbtiles" # database = "./OSMBright.mbtiles"
# create a database connection # create a database connection
conn = create_connection(database) conn = create_connection(database)
with conn: with conn:
print("Processing mbtiles..") print("Processing mbtiles..\n***********\nIf you find your y coordinates (filename.png) are incorrect, use the -tsm option\n***********\n")
select_all_images(conn) select_all_images(conn, tms)
def main(argv): def main(argv):
inputDir = '' inputDir = ''
tms = False
try: try:
opts, args = getopt.getopt(argv, "hi:o:", ["ifile="]) opts, args = getopt.getopt(argv, "hi:o:tms", ["ifile="])
except getopt.GetoptError: except getopt.GetoptError:
print ('mbtilesToPngs.py -i <path_to_file> (.mbtiles only)') print ('mbtilesToPngs.py -i <path_to_file> (.mbtiles only)')
sys.exit(2) sys.exit(2)
@ -102,11 +119,14 @@ def main(argv):
if not os.path.isfile(inputDir): if not os.path.isfile(inputDir):
print (inputDir, " file not found") print (inputDir, " file not found")
sys.exit() sys.exit()
elif opt in ("-tms"):
print("-tsm checked")
tms = True
if inputDir == '': if inputDir == '':
print ('mbtilesToPngs.py -i <path_to_file> (.mbtiles only)') print ('mbtilesToPngs.py -i <path_to_file> (.mbtiles only)')
sys.exit(2) sys.exit(2)
start = time.time() start = time.time()
beginConvertion(inputDir) beginConvertion(inputDir, tms)
end = time.time() end = time.time()
print("Time taken to complete: ", str(round((end - start), 2)), "s") print("Time taken to complete: ", str(round((end - start), 2)), "s")