remove openstreetmaps dependency
This commit is contained in:
parent
73c8839814
commit
b30ea9fa99
26456
hub/data/geolocation/cities15000.txt
Normal file
26456
hub/data/geolocation/cities15000.txt
Normal file
File diff suppressed because it is too large
Load Diff
|
@ -6,9 +6,9 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
||||||
Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
||||||
"""
|
"""
|
||||||
import math
|
import math
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import requests
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from trimesh import Trimesh
|
from trimesh import Trimesh
|
||||||
from trimesh import intersections
|
from trimesh import intersections
|
||||||
|
@ -298,19 +298,24 @@ class GeometryHelper:
|
||||||
"""
|
"""
|
||||||
Get Location from latitude and longitude
|
Get Location from latitude and longitude
|
||||||
"""
|
"""
|
||||||
url = 'https://nominatim.openstreetmap.org/reverse?lat={latitude}&lon={longitude}&format=json'
|
_data_path = Path(Path(__file__).parent.parent / 'data/geolocation/cities15000.txt').resolve()
|
||||||
response = requests.get(url.format(latitude=latitude, longitude=longitude))
|
latitude = float(latitude)
|
||||||
if response.status_code != 200:
|
longitude = float(longitude)
|
||||||
# This means something went wrong.
|
distance = math.inf
|
||||||
raise Exception('GET /tasks/ {}'.format(response.status_code))
|
country = 'Unknown'
|
||||||
|
|
||||||
response = response.json()
|
|
||||||
city = 'Unknown'
|
city = 'Unknown'
|
||||||
country = 'ca'
|
with open(_data_path, 'r') as f:
|
||||||
if 'city' in response['address']:
|
for line_number, line in enumerate(f):
|
||||||
city = response['address']['city']
|
fields = line.split('\t')
|
||||||
if 'country_code' in response['address']:
|
file_city_name = fields[2]
|
||||||
country = response['address']['country_code']
|
file_latitude = float(fields[4])
|
||||||
|
file_longitude = float(fields[5])
|
||||||
|
file_country_code = fields[8]
|
||||||
|
new_distance = math.sqrt(pow((latitude - file_latitude), 2) + pow((longitude - file_longitude), 2))
|
||||||
|
if distance > new_distance:
|
||||||
|
distance = new_distance
|
||||||
|
country = file_country_code
|
||||||
|
city = file_city_name
|
||||||
return Location(country, city)
|
return Location(country, city)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
Loading…
Reference in New Issue
Block a user