mirror of
https://github.com/enzet/map-machine.git
synced 2025-05-27 16:06:24 +02:00
Add --coordinates and --size arguments.
Construct boundary box from center coordinates and size.
This commit is contained in:
parent
cb440e8a8b
commit
b715e12924
8 changed files with 156 additions and 114 deletions
|
@ -20,7 +20,7 @@ from map_machine.flinger import Flinger
|
|||
from map_machine.icon import ShapeExtractor
|
||||
from map_machine.map_configuration import LabelMode, MapConfiguration
|
||||
from map_machine.osm_getter import NetworkError, get_osm
|
||||
from map_machine.osm_reader import OSMData, OSMNode, OSMReader, OverpassReader
|
||||
from map_machine.osm_reader import OSMData, OSMNode
|
||||
from map_machine.point import Occupied, Point
|
||||
from map_machine.road import Intersection, RoadPart
|
||||
from map_machine.scheme import Scheme
|
||||
|
@ -94,11 +94,11 @@ class Map:
|
|||
for tree in constructor.craters:
|
||||
tree.draw(self.svg, self.flinger)
|
||||
|
||||
self.draw_buildings(constructor)
|
||||
|
||||
for direction_sector in constructor.direction_sectors:
|
||||
direction_sector.draw(self.svg, self.scheme)
|
||||
|
||||
self.draw_buildings(constructor)
|
||||
|
||||
# All other points
|
||||
|
||||
occupied: Optional[Occupied]
|
||||
|
@ -201,74 +201,73 @@ class Map:
|
|||
intersection.draw(self.svg, True)
|
||||
|
||||
|
||||
def ui(options: argparse.Namespace) -> None:
|
||||
def ui(arguments: argparse.Namespace) -> None:
|
||||
"""
|
||||
Map Machine entry point.
|
||||
|
||||
:param options: command-line arguments
|
||||
:param arguments: command-line arguments
|
||||
"""
|
||||
configuration: MapConfiguration = MapConfiguration.from_options(
|
||||
options, int(options.zoom)
|
||||
arguments, int(arguments.zoom)
|
||||
)
|
||||
if not options.boundary_box and not options.input_file_name:
|
||||
logging.fatal("Specify either --boundary-box, or --input.")
|
||||
exit(1)
|
||||
|
||||
if options.boundary_box:
|
||||
boundary_box: BoundaryBox = BoundaryBox.from_text(options.boundary_box)
|
||||
|
||||
cache_path: Path = Path(options.cache)
|
||||
cache_path: Path = Path(arguments.cache)
|
||||
cache_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
input_file_names: list[Path]
|
||||
boundary_box: Optional[BoundaryBox] = None
|
||||
input_file_names: list[Path] = []
|
||||
|
||||
if options.input_file_name:
|
||||
input_file_names = list(map(Path, options.input_file_name))
|
||||
if arguments.input_file_names:
|
||||
input_file_names = list(map(Path, arguments.input_file_names))
|
||||
else:
|
||||
if arguments.boundary_box:
|
||||
boundary_box = BoundaryBox.from_text(arguments.boundary_box)
|
||||
else:
|
||||
coordinates: np.ndarray = np.array(
|
||||
list(map(float, arguments.coordinates.split(",")))
|
||||
)
|
||||
width, height = np.array(
|
||||
list(map(float, arguments.size.split(",")))
|
||||
)
|
||||
boundary_box = BoundaryBox.from_coordinates(
|
||||
coordinates, configuration.zoom_level, width, height
|
||||
)
|
||||
|
||||
try:
|
||||
cache_file_path: Path = (
|
||||
cache_path / f"{boundary_box.get_format()}.osm"
|
||||
)
|
||||
get_osm(boundary_box, cache_file_path)
|
||||
input_file_names = [cache_file_path]
|
||||
except NetworkError as e:
|
||||
logging.fatal(e.message)
|
||||
exit(1)
|
||||
input_file_names = [cache_file_path]
|
||||
|
||||
scheme: Scheme = Scheme(workspace.DEFAULT_SCHEME_PATH)
|
||||
min_: np.ndarray
|
||||
max_: np.ndarray
|
||||
osm_data: OSMData
|
||||
view_box: BoundaryBox
|
||||
|
||||
if input_file_names[0].name.endswith(".json"):
|
||||
reader: OverpassReader = OverpassReader()
|
||||
reader.parse_json_file(input_file_names[0])
|
||||
osm_data: OSMData = OSMData()
|
||||
|
||||
osm_data = reader.osm_data
|
||||
view_box = boundary_box
|
||||
else:
|
||||
osm_reader = OSMReader()
|
||||
for input_file_name in input_file_names:
|
||||
if not input_file_name.is_file():
|
||||
logging.fatal(f"No such file: {input_file_name}.")
|
||||
exit(1)
|
||||
|
||||
for file_name in input_file_names:
|
||||
if not file_name.is_file():
|
||||
logging.fatal(f"No such file: {file_name}.")
|
||||
exit(1)
|
||||
|
||||
osm_reader.parse_osm_file(file_name)
|
||||
|
||||
osm_data = osm_reader.osm_data
|
||||
|
||||
if options.boundary_box:
|
||||
view_box = boundary_box
|
||||
if input_file_name.name.endswith(".json"):
|
||||
osm_data.parse_overpass(input_file_name)
|
||||
else:
|
||||
view_box = osm_data.view_box
|
||||
osm_data.parse_osm_file(input_file_name)
|
||||
|
||||
flinger: Flinger = Flinger(view_box, options.zoom, osm_data.equator_length)
|
||||
view_box: BoundaryBox = boundary_box if boundary_box else osm_data.view_box
|
||||
|
||||
flinger: Flinger = Flinger(
|
||||
view_box, arguments.zoom, osm_data.equator_length
|
||||
)
|
||||
size: np.ndarray = flinger.size
|
||||
|
||||
svg: svgwrite.Drawing = svgwrite.Drawing(
|
||||
options.output_file_name, size=size
|
||||
arguments.output_file_name, size=size
|
||||
)
|
||||
icon_extractor: ShapeExtractor = ShapeExtractor(
|
||||
workspace.ICONS_PATH, workspace.ICONS_CONFIG_PATH
|
||||
|
@ -288,6 +287,6 @@ def ui(options: argparse.Namespace) -> None:
|
|||
)
|
||||
painter.draw(constructor)
|
||||
|
||||
logging.info(f"Writing output SVG to {options.output_file_name}...")
|
||||
with open(options.output_file_name, "w") as output_file:
|
||||
logging.info(f"Writing output SVG to {arguments.output_file_name}...")
|
||||
with open(arguments.output_file_name, "w") as output_file:
|
||||
svg.write(output_file)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue