diff --git a/backend/src/utils/cluster_manager.py b/backend/src/utils/cluster_manager.py index ed79c86..9b9570b 100644 --- a/backend/src/utils/cluster_manager.py +++ b/backend/src/utils/cluster_manager.py @@ -224,6 +224,9 @@ class ClusterManager: for elem in result.elements(): location = (elem.centerLat(), elem.centerLon()) + # Skip if element has neither name or location + if elem.tag('name') is None : + continue if location[0] is None : location = (elem.lat(), elem.lon()) if location[0] is None : diff --git a/backend/src/utils/landmarks_manager.py b/backend/src/utils/landmarks_manager.py index 92d01bb..5330bb7 100644 --- a/backend/src/utils/landmarks_manager.py +++ b/backend/src/utils/landmarks_manager.py @@ -261,97 +261,71 @@ class LandmarkManager: if 'building:part' in elem.tags().keys() and elem.tag('building:part') == 'yes': continue - elem_type = landmarktype # Add the landmark type as 'sightseeing, - n_tags = len(elem.tags().keys()) # Add number of tags - score = n_tags**self.tag_exponent # Add score - website_url = None - image_url = None - name_en = None + elem_type = landmarktype # Add the landmark type as 'sightseeing, + n_tags = len(elem.tags().keys()) # Add number of tags + score = n_tags**self.tag_exponent # Add score + duration = 5 # Set base duration to 5 minutes + skip = False # Set skipping parameter to false + tag_values = set(elem.tags().values()) # Store tag values - # Adjust scoring, browse through tag keys - skip = False + + # Use simple tags : + image_url = elem.tag('image') + website_url = elem.tag('website') + if website_url is None : + website_url = elem.tag('wikipedia') + name_en = elem.tag('name:en') + + if elem_type != "nature" and elem.tag('leisure') == "park": + elem_type = "nature" + + # Skip element if it is an administrative boundary or a disused thing or it is an appartement and useless amenities + if elem.tag('boundary') is not None or elem.tag('disused') is not None: + continue + if 'apartments' in elem.tags().values(): + continue + if elem.tag('historic') is not None and elem.tag('historic') in ['manor', 'optical_telegraph', 'pound', 'shieling', 'wayside_cross']: + continue + + # Adjust scoring, browse through tag keys using wildcards for tag_key in elem.tags().keys(): if "pay" in tag_key: # payment options are misleading and should not count for the scoring. score += self.pay_bonus - if "disused" in tag_key: - # skip disused amenities - skip = True - break - if "building:" in tag_key: # do not count the building description as being particularly useful n_tags -= 1 - - - if "boundary" in tag_key: - # skip "areas" like administrative boundaries and stuff - skip = True - break - - if "historic" in tag_key and elem.tag('historic') in ['manor', 'optical_telegraph', 'pound', 'shieling', 'wayside_cross']: - # skip useless amenities - skip = True - break - - if "name" in tag_key : - score += self.name_bonus if "wiki" in tag_key: # wikipedia entries count more score += self.wikipedia_bonus - if "image" in tag_key: - # images must count more - score += self.image_bonus - - if elem_type != "nature": - if "leisure" in tag_key and elem.tag('leisure') == "park": - elem_type = "nature" - if landmarktype != "shopping": if "shop" in tag_key: skip = True break - - if tag_key == "building" and elem.tag('building') in ['retail', 'supermarket', 'parking']: - skip = True - break - - # Extract image, website and english name - if tag_key in ['website', 'contact:website']: - website_url = elem.tag(tag_key) - if tag_key == 'image': - image_url = elem.tag('image') - if tag_key =='name:en': - name_en = elem.tag('name:en') + # if tag_key == "building" and elem.tag('building') in ['retail', 'supermarket', 'parking']: + # skip = True + # break if skip: continue - # Don't visit random apartments - if 'apartments' in elem.tags().values(): - continue - score = score_function(score) - if "place_of_worship" in elem.tags().values() : - if "cathedral" not in elem.tags().values() : - score = score * self.church_coeff - duration = 5 - else : + + if "place_of_worship" in tag_values : + if 'cathedral' in tag_values : duration = 10 + else : + score *= self.church_coeff - elif 'viewpoint' in elem.tags().values() : + elif 'viewpoint' in tag_values : # viewpoints must count more score = score * self.viewpoint_bonus - duration = 10 - elif "museum" in elem.tags().values() or "aquarium" in elem.tags().values() or "planetarium" in elem.tags().values(): + elif "museum" in tag_values or "aquarium" in tag_values or "planetarium" in tag_values: duration = 60 - - else: - duration = 5 # finally create our own landmark object landmark = Landmark( diff --git a/backend/src/utils/test.py b/backend/src/utils/test.py new file mode 100644 index 0000000..aca019b --- /dev/null +++ b/backend/src/utils/test.py @@ -0,0 +1,27 @@ +from OSMPythonTools.overpass import Overpass, overpassQueryBuilder + + + +overpass = Overpass() +query = overpassQueryBuilder( + bbox = (45.7300, 4.7900, 45.8000, 4.8600), + elementType = ['way'], + # selector can in principle be a list already, + # but it generates the intersection of the queries + # we want the union + selector = '"historic"="building"', + includeCenter = True, + out = 'body' + ) + + +res = overpass.query(query) + + +# for elem in res.elements() : +elem = res.elements()[1] + +tags = elem.tags() + +test = elem.tag('sgehs') +print(test)