This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ENTRY: | |
if __name__ == "__main__": | |
download_all() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# MASTER: | |
def download_all(): | |
for region in PARAM['regions']: | |
try: | |
logging.info("Downloading region '{}'...".format(region)) | |
download(region) | |
logging.info("Download OK!") | |
except urllib.error.URLError: | |
logging.exception("Download failed (no connection or wrong URL?).") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SLAVES: | |
def download(region): | |
bbox = PARAM['regions'][region] | |
url = PARAM['API-URL'].format(bbox="{0},{1},{2},{3}".format(*bbox)) | |
out = OFILE['OSM'].format(region=region) | |
meta = { | |
'Region': region, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# AUXILIARY: | |
# https://stackoverflow.com/questions/34491808/how-to-get-the-current-scripts-code-in-python | |
THIS = inspect.getsource(inspect.getmodule(inspect.currentframe())) | |
# Set logger verbosity and output format | |
logging.basicConfig( | |
level=logging.DEBUG, | |
format="%(levelname)-8s [%(asctime)s] : %(message)s", | |
datefmt="%Y%m%d %H:%M:%S %Z" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PARAMETERS: | |
PARAM = { | |
# Bounding box to download [left, bottom, right, top] | |
# https://wiki.openstreetmap.org/wiki/API_v0.6 | |
'regions': { | |
'kaohsiung_small': [120.2206, 22.4827, 120.4308, 22.7578], | |
'kaohsiung_large': [119.9377, 22.1645, 120.8084, 23.3347], | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for fn in OFILE.values(): | |
os.makedirs(os.path.dirname(fn).format(), exist_ok=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# OUTPUT FILES: | |
OFILE = { | |
# Put the downloaded *.osm files here | |
'OSM': "OUTPUT/maps/UV/{region}.osm", | |
# Record meta-info here | |
'OSM-meta': "OUTPUT/maps/{region}_meta.txt", | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# INPUT FILES: | |
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# IMPORTS: | |
import os | |
import json | |
import inspect | |
import logging | |
import datetime as dt | |
import urllib.request, urllib.error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# RA, 2019-01-15 | |
# Download an OpenStreetMap file based on a lat-lon bounding box | |
# License: CC0 -- "No rights reserved" |
NewerOlder