mirror of
https://github.com/hyperknot/openfreemap.git
synced 2026-05-21 14:02:15 +00:00
simplify extract_mbtiles.py
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
import shutil
|
import shutil
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import sys
|
import sys
|
||||||
@@ -34,9 +33,6 @@ def cli(mbtiles_path: Path, dir_path: Path):
|
|||||||
write_dedupl_files(c, dir_path=dir_path)
|
write_dedupl_files(c, dir_path=dir_path)
|
||||||
write_tile_files(c, dir_path=dir_path)
|
write_tile_files(c, dir_path=dir_path)
|
||||||
|
|
||||||
# planetiler has missing tiles by design, so disabling this
|
|
||||||
# assert_all_tiles_present(mbtiles_path, dir_path)
|
|
||||||
|
|
||||||
write_metadata(c, dir_path=dir_path)
|
write_metadata(c, dir_path=dir_path)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
@@ -125,24 +121,6 @@ def write_tile_files(c, *, dir_path):
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
def assert_all_tiles_present(mbtiles_path, dir_path):
|
|
||||||
"""
|
|
||||||
If it's a full planet run,
|
|
||||||
make sure there are exactly the right number of files generated.
|
|
||||||
"""
|
|
||||||
|
|
||||||
if 'planet' in mbtiles_path.resolve().parent.name:
|
|
||||||
assert count_files(dir_path / 'tiles') == calculate_tiles_sum(14)
|
|
||||||
print(f'Tile number: {calculate_tiles_sum(14)} - OK')
|
|
||||||
|
|
||||||
|
|
||||||
def count_files(folder):
|
|
||||||
total = 0
|
|
||||||
for root, dirs, files in os.walk(folder):
|
|
||||||
total += len(files)
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def get_fixed_dedupl_name(bug_fix_dict, dedupl_path):
|
def get_fixed_dedupl_name(bug_fix_dict, dedupl_path):
|
||||||
if dedupl_path in bug_fix_dict:
|
if dedupl_path in bug_fix_dict:
|
||||||
return dedupl_path.with_name(f'{dedupl_path.name}-{bug_fix_dict[dedupl_path]}')
|
return dedupl_path.with_name(f'{dedupl_path.name}-{bug_fix_dict[dedupl_path]}')
|
||||||
@@ -166,16 +144,5 @@ def flip_y(zoom, y):
|
|||||||
return (2**zoom - 1) - y
|
return (2**zoom - 1) - y
|
||||||
|
|
||||||
|
|
||||||
def calculate_tiles(zoom_level):
|
|
||||||
return (2**zoom_level) ** 2
|
|
||||||
|
|
||||||
|
|
||||||
def calculate_tiles_sum(zoom_level):
|
|
||||||
"""
|
|
||||||
Sum of tiles up to zoom level (geometric series)
|
|
||||||
"""
|
|
||||||
return (4 ** (zoom_level + 1) - 1) // 3
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
cli()
|
cli()
|
||||||
|
|||||||
Reference in New Issue
Block a user