mirror of
https://github.com/enzet/map-machine.git
synced 2025-06-19 03:01:51 +02:00
Issue #62: add cache path option.
This commit is contained in:
parent
376087949a
commit
e18419cc3a
4 changed files with 19 additions and 8 deletions
10
roentgen.py
10
roentgen.py
|
@ -41,17 +41,19 @@ def main(argv) -> None:
|
||||||
if not options:
|
if not options:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
input_file_names: List[Path]
|
cache_path: Path = Path(options.cache)
|
||||||
|
cache_path.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
os.makedirs("map", exist_ok=True)
|
input_file_names: List[Path]
|
||||||
|
|
||||||
if options.input_file_name:
|
if options.input_file_name:
|
||||||
input_file_names = list(map(Path, options.input_file_name))
|
input_file_names = list(map(Path, options.input_file_name))
|
||||||
else:
|
else:
|
||||||
content = get_osm(options.boundary_box)
|
content = get_osm(options.boundary_box, cache_path)
|
||||||
if not content:
|
if not content:
|
||||||
error("cannot download OSM data")
|
error("cannot download OSM data")
|
||||||
input_file_names = ["map" / Path(options.boundary_box + ".osm")]
|
sys.exit(1)
|
||||||
|
input_file_names = [cache_path / f"{options.boundary_box}.osm"]
|
||||||
|
|
||||||
scheme: Scheme = Scheme(Path(TAGS_FILE_NAME))
|
scheme: Scheme = Scheme(Path(TAGS_FILE_NAME))
|
||||||
min_: np.array
|
min_: np.array
|
||||||
|
|
|
@ -15,14 +15,17 @@ __author__ = "Sergey Vartanov"
|
||||||
__email__ = "me@enzet.ru"
|
__email__ = "me@enzet.ru"
|
||||||
|
|
||||||
|
|
||||||
def get_osm(boundary_box: str, to_update: bool = False) -> Optional[str]:
|
def get_osm(
|
||||||
|
boundary_box: str, cache_path: Path, to_update: bool = False
|
||||||
|
) -> Optional[str]:
|
||||||
"""
|
"""
|
||||||
Download OSM data from the web or get if from the cache.
|
Download OSM data from the web or get if from the cache.
|
||||||
|
|
||||||
:param boundary_box: borders of the map part to download
|
:param boundary_box: borders of the map part to download
|
||||||
|
:param cache_path: cache directory to store downloaded OSM files
|
||||||
:param to_update: update cache files
|
:param to_update: update cache files
|
||||||
"""
|
"""
|
||||||
result_file_name: Path = "map" / Path(boundary_box + ".osm")
|
result_file_name: Path = cache_path / f"{boundary_box}.osm"
|
||||||
|
|
||||||
if not to_update and result_file_name.is_file():
|
if not to_update and result_file_name.is_file():
|
||||||
return result_file_name.open().read()
|
return result_file_name.open().read()
|
||||||
|
@ -30,7 +33,8 @@ def get_osm(boundary_box: str, to_update: bool = False) -> Optional[str]:
|
||||||
matcher = re.match(
|
matcher = re.match(
|
||||||
"(?P<left>[0-9.-]*),(?P<bottom>[0-9.-]*)," +
|
"(?P<left>[0-9.-]*),(?P<bottom>[0-9.-]*)," +
|
||||||
"(?P<right>[0-9.-]*),(?P<top>[0-9.-]*)",
|
"(?P<right>[0-9.-]*),(?P<top>[0-9.-]*)",
|
||||||
boundary_box)
|
boundary_box
|
||||||
|
)
|
||||||
|
|
||||||
if not matcher:
|
if not matcher:
|
||||||
error("invalid boundary box")
|
error("invalid boundary box")
|
||||||
|
|
|
@ -98,7 +98,7 @@ class Tile:
|
||||||
f"{min(lon1, lon2):.3f},{min(lat1, lat2):.3f},"
|
f"{min(lon1, lon2):.3f},{min(lat1, lat2):.3f},"
|
||||||
f"{max(lon1, lon2):.3f},{max(lat1, lat2):.3f}"
|
f"{max(lon1, lon2):.3f},{max(lat1, lat2):.3f}"
|
||||||
)
|
)
|
||||||
content = get_osm(boundary_box)
|
content = get_osm(boundary_box, Path("cache"))
|
||||||
if not content:
|
if not content:
|
||||||
error("cannot download OSM data")
|
error("cannot download OSM data")
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -47,6 +47,11 @@ def parse_options(args) -> argparse.Namespace:
|
||||||
default=18,
|
default=18,
|
||||||
dest="scale",
|
dest="scale",
|
||||||
type=float)
|
type=float)
|
||||||
|
parser.add_argument(
|
||||||
|
"--cache",
|
||||||
|
help="path for temporary OSM files",
|
||||||
|
default="cache"
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--labels",
|
"--labels",
|
||||||
help="label drawing mode: `no`, `main`, or `all`",
|
help="label drawing mode: `no`, `main`, or `all`",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue