From 53ba0d784530354cca9c99a732be931156e3d50d Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Wed, 16 Jun 2021 14:33:18 +0200 Subject: [PATCH] Show 'part of' in candidate list --- frontend/App.vue | 5 +++++ web_view.py | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/frontend/App.vue b/frontend/App.vue index 0a1923d..d7c08be 100644 --- a/frontend/App.vue +++ b/frontend/App.vue @@ -146,6 +146,11 @@
address nodes: {{ osm.address_list.join("; ") }}
+ + +
part of: {{ osm.part_of.join("; ") }} +
+ diff --git a/web_view.py b/web_view.py index 980e37f..54a99c0 100755 --- a/web_view.py +++ b/web_view.py @@ -951,6 +951,21 @@ def get_address_nodes_within_building(building, bbox): return [node.tags for node in q] +def get_part_of(thing, bbox): + db_bbox = make_envelope(bbox) + ewkt = thing.as_EWKT + q = model.Polygon.query.filter( + func.ST_Intersects(db_bbox, model.Polygon.way), + func.ST_Covers(model.Polygon.way, func.ST_GeomFromEWKT(ewkt)), + or_( + model.Polygon.tags.has_key("landuse"), + model.Polygon.tags.has_key("amenity"), + ), + model.Polygon.tags.has_key("name"), + ) + + return [polygon.tags for polygon in q] + def address_from_tags(tags): keys = ["street", "housenumber"] if g.street_number_first: @@ -989,6 +1004,10 @@ def api_find_osm_candidates(item_id): if hasattr(osm, 'area'): cur["area"] = osm.area + part_of = [i["name"] for i in get_part_of(osm, bounds) if i["name"] != name] + if part_of: + cur["part_of"] = part_of + nearby.append(cur) t1 = time() - t0