From 9188e99d502d94bf9c054d5b34d098b4b109a2c8 Mon Sep 17 00:00:00 2001 From: Sergey Vartanov Date: Thu, 2 Dec 2021 08:10:29 +0300 Subject: [PATCH] Add tag verification. --- map_machine/osm/osm_reader.py | 14 ++++++++++++++ map_machine/scheme.py | 6 ++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/map_machine/osm/osm_reader.py b/map_machine/osm/osm_reader.py index af3b91a..bf1215d 100644 --- a/map_machine/osm/osm_reader.py +++ b/map_machine/osm/osm_reader.py @@ -107,6 +107,20 @@ class Tagged: return None + def verify(self) -> bool: + """Check key and value types.""" + is_well_formed: bool = True + + for value, key in self.tags.items(): + if not isinstance(key, str): + logging.warning(f"Not string key {key}.") + is_well_formed = False + if not isinstance(value, str): + logging.warning(f"Not string value {value}.") + is_well_formed = False + + return is_well_formed + @dataclass class OSMNode(Tagged): diff --git a/map_machine/scheme.py b/map_machine/scheme.py index b27bd37..dc211d0 100644 --- a/map_machine/scheme.py +++ b/map_machine/scheme.py @@ -14,7 +14,7 @@ from colour import Color from map_machine.feature.direction import DirectionSet from map_machine.map_configuration import MapConfiguration, LabelMode -from map_machine.osm.osm_reader import Tags +from map_machine.osm.osm_reader import Tagged, Tags from map_machine.pictogram.icon import ( DEFAULT_COLOR, DEFAULT_SHAPE_ID, @@ -102,7 +102,7 @@ def match_location(restrictions: dict[str, str], country: str) -> bool: return True -class Matcher: +class Matcher(Tagged): """Tag matching.""" def __init__( @@ -126,6 +126,8 @@ class Matcher: if "location_restrictions" in structure: self.location_restrictions = structure["location_restrictions"] + self.verify() + def check_zoom_level(self, zoom_level: float) -> bool: """Check whether zoom level is matching.""" return (