From e3cf575f0dbeca98f7de22b1e3a18dbaf1a3a3d3 Mon Sep 17 00:00:00 2001 From: Sergey Vartanov Date: Thu, 16 Sep 2021 07:48:31 +0300 Subject: [PATCH] Fix arguments. --- map_machine/mapper.py | 8 +++++++- map_machine/scheme/default.yml | 13 +++++++------ map_machine/tile.py | 17 +++++++++++------ tests/test_command_line.py | 3 ++- tests/test_osm_reader.py | 21 ++++++++++----------- 5 files changed, 37 insertions(+), 25 deletions(-) diff --git a/map_machine/mapper.py b/map_machine/mapper.py index 3d88881..1cead1b 100644 --- a/map_machine/mapper.py +++ b/map_machine/mapper.py @@ -221,7 +221,7 @@ def ui(arguments: argparse.Namespace) -> None: else: if arguments.boundary_box: boundary_box = BoundaryBox.from_text(arguments.boundary_box) - else: + elif arguments.coordinates and arguments.size: coordinates: np.ndarray = np.array( list(map(float, arguments.coordinates.split(","))) ) @@ -231,6 +231,12 @@ def ui(arguments: argparse.Namespace) -> None: boundary_box = BoundaryBox.from_coordinates( coordinates, configuration.zoom_level, width, height ) + else: + logging.fatal( + "Specify either --input, or --boundary-box, or --coordinates " + "and --size." + ) + exit(1) try: cache_file_path: Path = ( diff --git a/map_machine/scheme/default.yml b/map_machine/scheme/default.yml index e22cae4..1ce88dc 100644 --- a/map_machine/scheme/default.yml +++ b/map_machine/scheme/default.yml @@ -1429,6 +1429,7 @@ roads: default_width: 15 border_color: motorway_border_color color: motorway_color + priority: 41.8 - tags: {highway: trunk} default_width: 13 border_color: road_border_color @@ -1437,31 +1438,31 @@ roads: default_width: 11 border_color: primary_border_color color: primary_color - priority: 41.9 + priority: 41.7 - tags: {highway: motorway_link} default_width: 9 border_color: motorway_border_color color: motorway_color - priority: 41 + priority: 41.8 - tags: {highway: secondary} default_width: 9 border_color: secondary_border_color - priority: 41.8 + priority: 41.6 color: secondary_color - tags: {highway: secondary_link} default_width: 9 border_color: secondary_border_color - priority: 41.8 + priority: 41.6 color: secondary_color - tags: {highway: tertiary} default_width: 7 border_color: tertiary_border_color - priority: 41.7 + priority: 41.5 color: tertiary_color - tags: {highway: tertiary_link} default_width: 7 border_color: tertiary_border_color - priority: 41.7 + priority: 41.5 color: tertiary_color - tags: {highway: unclassified} default_width: 5 diff --git a/map_machine/tile.py b/map_machine/tile.py index a9e9f65..4ac46a8 100644 --- a/map_machine/tile.py +++ b/map_machine/tile.py @@ -22,7 +22,7 @@ from map_machine.icon import ShapeExtractor from map_machine.map_configuration import MapConfiguration from map_machine.mapper import Map from map_machine.osm_getter import NetworkError, get_osm -from map_machine.osm_reader import OSMData, OSMReader +from map_machine.osm_reader import OSMData from map_machine.scheme import Scheme from map_machine.workspace import workspace @@ -104,7 +104,10 @@ class Tile: ) get_osm(self.get_extended_boundary_box(), cache_file_path) - return OSMReader().parse_osm_file(cache_file_path) + osm_data: OSMData = OSMData() + osm_data.parse_osm_file(cache_file_path) + + return osm_data def get_file_name(self, directory_name: Path) -> Path: """Get tile output SVG file path.""" @@ -258,7 +261,10 @@ class Tiles: ) get_osm(self.boundary_box, cache_file_path) - return OSMReader().parse_osm_file(cache_file_path) + osm_data: OSMData = OSMData() + osm_data.parse_osm_file(cache_file_path) + + return osm_data def draw_separately( self, directory: Path, cache_path: Path, configuration: MapConfiguration @@ -461,9 +467,8 @@ def ui(options: argparse.Namespace) -> None: min_zoom_level: int = min(zoom_levels) if options.input_file_name: - osm_reader: OSMReader = OSMReader() - osm_reader.parse_osm_file(Path(options.input_file_name)) - osm_data: OSMData = osm_reader.osm_data + osm_data: OSMData = OSMData() + osm_data.parse_osm_file(Path(options.input_file_name)) for zoom_level in zoom_levels: configuration: MapConfiguration = MapConfiguration.from_options( options, zoom_level diff --git a/tests/test_command_line.py b/tests/test_command_line.py index 3a32039..6da6104 100644 --- a/tests/test_command_line.py +++ b/tests/test_command_line.py @@ -33,7 +33,8 @@ def test_wrong_render_arguments() -> None: """Test `render` command with wrong arguments.""" error_run( ["render", "-z", "17"], - b"CRITICAL Specify either --boundary-box, or --input.\n", + b"CRITICAL Specify either --input, or --boundary-box, or --coordinates " + b"and --size.\n", ) diff --git a/tests/test_osm_reader.py b/tests/test_osm_reader.py index 24f99ad..8aa1330 100644 --- a/tests/test_osm_reader.py +++ b/tests/test_osm_reader.py @@ -6,7 +6,6 @@ import numpy as np from map_machine.osm_reader import ( OSMData, OSMNode, - OSMReader, OSMRelation, OSMWay, parse_levels, @@ -18,8 +17,8 @@ __email__ = "me@enzet.ru" def test_node() -> None: """Test OSM node parsing from XML.""" - reader: OSMReader = OSMReader() - osm_data: OSMData = reader.parse_osm_text( + osm_data: OSMData = OSMData() + osm_data.parse_osm_text( """ @@ -33,8 +32,8 @@ def test_node() -> None: def test_node_with_tag() -> None: """Test OSM node parsing from XML.""" - reader = OSMReader() - osm_data: OSMData = reader.parse_osm_text( + osm_data: OSMData = OSMData() + osm_data.parse_osm_text( """ @@ -51,8 +50,8 @@ def test_node_with_tag() -> None: def test_way() -> None: """Test OSM way parsing from XML.""" - reader: OSMReader = OSMReader() - osm_data: OSMData = reader.parse_osm_text( + osm_data: OSMData = OSMData() + osm_data.parse_osm_text( """ @@ -65,8 +64,8 @@ def test_way() -> None: def test_nodes() -> None: """Test OSM node parsing from XML.""" - reader = OSMReader() - osm_data: OSMData = reader.parse_osm_text( + osm_data: OSMData = OSMData() + osm_data.parse_osm_text( """ @@ -84,8 +83,8 @@ def test_nodes() -> None: def test_relation() -> None: """Test OSM node parsing from XML.""" - reader: OSMReader = OSMReader() - osm_data: OSMData = reader.parse_osm_text( + osm_data: OSMData = OSMData() + osm_data.parse_osm_text( """