From e62dd4d1d604225235b81f82406e60a7f7520a9c Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Fri, 2 Jul 2021 11:14:37 +0200 Subject: [PATCH] Improve OSM name handling --- matcher/api.py | 4 ++-- matcher/model.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/matcher/api.py b/matcher/api.py index e24dd3c..d927e7a 100644 --- a/matcher/api.py +++ b/matcher/api.py @@ -421,8 +421,8 @@ def find_osm_candidates(item, bounds): for osm, dist in get_nearby(bounds, item): tags = osm.tags tags.pop("way_area", None) - name = osm.name or tags.get("addr:housename") or tags.get("inscription") - if not name and "addr:housenumber" in tags and "addr:street" in tags: + name = osm.display_name() + if not name and osm.has_street_address: name = address_from_tags(tags) if isinstance(osm, model.Polygon) and "building" in osm.tags: diff --git a/matcher/model.py b/matcher/model.py index 403ff70..5671bb0 100644 --- a/matcher/model.py +++ b/matcher/model.py @@ -232,6 +232,20 @@ class MapMixin: def as_EWKT(cls): return column_property(func.ST_AsEWKT(cls.way), deferred=True) + @hybrid_property + def has_street_address(self): + return ("addr:housenumber" in self.tags + and "addr:street" in self.tags) + + def display_name(self): + for key in 'bridge:name', 'tunnel:name', 'lock_name': + if key in self.tags: + return self.tags[key] + + return (self.name + or self.tags.get("addr:housename") + or self.tags.get("inscription")) + def geojson(self): return json.loads(self.geojson_str)