cleaning up
This commit is contained in:
parent
160059d94b
commit
a0a3d76b78
backend/src/utils
@ -224,6 +224,9 @@ class ClusterManager:
|
|||||||
for elem in result.elements():
|
for elem in result.elements():
|
||||||
location = (elem.centerLat(), elem.centerLon())
|
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 :
|
if location[0] is None :
|
||||||
location = (elem.lat(), elem.lon())
|
location = (elem.lat(), elem.lon())
|
||||||
if location[0] is None :
|
if location[0] is None :
|
||||||
|
@ -261,98 +261,72 @@ class LandmarkManager:
|
|||||||
if 'building:part' in elem.tags().keys() and elem.tag('building:part') == 'yes':
|
if 'building:part' in elem.tags().keys() and elem.tag('building:part') == 'yes':
|
||||||
continue
|
continue
|
||||||
|
|
||||||
elem_type = landmarktype # Add the landmark type as 'sightseeing,
|
elem_type = landmarktype # Add the landmark type as 'sightseeing,
|
||||||
n_tags = len(elem.tags().keys()) # Add number of tags
|
n_tags = len(elem.tags().keys()) # Add number of tags
|
||||||
score = n_tags**self.tag_exponent # Add score
|
score = n_tags**self.tag_exponent # Add score
|
||||||
website_url = None
|
duration = 5 # Set base duration to 5 minutes
|
||||||
image_url = None
|
skip = False # Set skipping parameter to false
|
||||||
name_en = None
|
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():
|
for tag_key in elem.tags().keys():
|
||||||
if "pay" in tag_key:
|
if "pay" in tag_key:
|
||||||
# payment options are misleading and should not count for the scoring.
|
# payment options are misleading and should not count for the scoring.
|
||||||
score += self.pay_bonus
|
score += self.pay_bonus
|
||||||
|
|
||||||
if "disused" in tag_key:
|
|
||||||
# skip disused amenities
|
|
||||||
skip = True
|
|
||||||
break
|
|
||||||
|
|
||||||
if "building:" in tag_key:
|
if "building:" in tag_key:
|
||||||
# do not count the building description as being particularly useful
|
# do not count the building description as being particularly useful
|
||||||
n_tags -= 1
|
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:
|
if "wiki" in tag_key:
|
||||||
# wikipedia entries count more
|
# wikipedia entries count more
|
||||||
score += self.wikipedia_bonus
|
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 landmarktype != "shopping":
|
||||||
if "shop" in tag_key:
|
if "shop" in tag_key:
|
||||||
skip = True
|
skip = True
|
||||||
break
|
break
|
||||||
|
# if tag_key == "building" and elem.tag('building') in ['retail', 'supermarket', 'parking']:
|
||||||
if tag_key == "building" and elem.tag('building') in ['retail', 'supermarket', 'parking']:
|
# skip = True
|
||||||
skip = True
|
# break
|
||||||
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 skip:
|
if skip:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Don't visit random apartments
|
|
||||||
if 'apartments' in elem.tags().values():
|
|
||||||
continue
|
|
||||||
|
|
||||||
score = score_function(score)
|
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 :
|
|
||||||
duration = 10
|
|
||||||
|
|
||||||
elif 'viewpoint' in elem.tags().values() :
|
if "place_of_worship" in tag_values :
|
||||||
|
if 'cathedral' in tag_values :
|
||||||
|
duration = 10
|
||||||
|
else :
|
||||||
|
score *= self.church_coeff
|
||||||
|
|
||||||
|
elif 'viewpoint' in tag_values :
|
||||||
# viewpoints must count more
|
# viewpoints must count more
|
||||||
score = score * self.viewpoint_bonus
|
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
|
duration = 60
|
||||||
|
|
||||||
else:
|
|
||||||
duration = 5
|
|
||||||
|
|
||||||
# finally create our own landmark object
|
# finally create our own landmark object
|
||||||
landmark = Landmark(
|
landmark = Landmark(
|
||||||
name = name,
|
name = name,
|
||||||
|
27
backend/src/utils/test.py
Normal file
27
backend/src/utils/test.py
Normal file
@ -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)
|
Loading…
x
Reference in New Issue
Block a user