mirror of
https://github.com/hyperknot/openfreemap.git
synced 2026-05-21 14:02:15 +00:00
54 lines
1.4 KiB
Python
54 lines
1.4 KiB
Python
import os
|
|
import shutil
|
|
import subprocess
|
|
from datetime import datetime, timezone
|
|
from pathlib import Path
|
|
|
|
from tile_gen_lib.config import config
|
|
|
|
|
|
def run_planetiler(area: str) -> Path:
|
|
assert area in config.areas
|
|
|
|
date = datetime.now(tz=timezone.utc).strftime('%Y%m%d_%H%M%S')
|
|
|
|
# delete all previous runs for the given area
|
|
shutil.rmtree(config.runs_dir / area, ignore_errors=True)
|
|
|
|
run_folder = config.runs_dir / area / f'{date}_pt'
|
|
run_folder.mkdir(parents=True, exist_ok=True)
|
|
|
|
os.chdir(run_folder)
|
|
|
|
java_memory_gb = 30 if area == 'planet' else 1
|
|
|
|
command = [
|
|
'java',
|
|
f'-Xmx{java_memory_gb}g',
|
|
'-jar',
|
|
config.planetiler_path,
|
|
f'--area={area}',
|
|
'--download',
|
|
'--download-threads=10',
|
|
'--download-chunk-size-mb=1000',
|
|
'--fetch-wikidata',
|
|
'--output=tiles.mbtiles',
|
|
'--nodemap-type=array',
|
|
'--storage=mmap',
|
|
'--force',
|
|
]
|
|
|
|
if area == 'planet':
|
|
command += '--bounds=planet'
|
|
|
|
out_path = run_folder / 'planetiler.out'
|
|
err_path = run_folder / 'planetiler.err'
|
|
|
|
with out_path.open('w') as out_file, err_path.open('w') as err_file:
|
|
subprocess.run(command, stdout=out_file, stderr=err_file, check=True, cwd=run_folder)
|
|
|
|
shutil.rmtree(run_folder / 'data', ignore_errors=True)
|
|
print('planetiler.jar DONE')
|
|
|
|
return run_folder
|