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
|
||||
"""
|
||||
import math
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
import requests
|
||||
from PIL import Image
|
||||
from trimesh import Trimesh
|
||||
from trimesh import intersections
|
||||
|
@ -298,19 +298,24 @@ class GeometryHelper:
|
|||
"""
|
||||
Get Location from latitude and longitude
|
||||
"""
|
||||
url = 'https://nominatim.openstreetmap.org/reverse?lat={latitude}&lon={longitude}&format=json'
|
||||
response = requests.get(url.format(latitude=latitude, longitude=longitude))
|
||||
if response.status_code != 200:
|
||||
# This means something went wrong.
|
||||
raise Exception('GET /tasks/ {}'.format(response.status_code))
|
||||
|
||||
response = response.json()
|
||||
_data_path = Path(Path(__file__).parent.parent / 'data/geolocation/cities15000.txt').resolve()
|
||||
latitude = float(latitude)
|
||||
longitude = float(longitude)
|
||||
distance = math.inf
|
||||
country = 'Unknown'
|
||||
city = 'Unknown'
|
||||
country = 'ca'
|
||||
if 'city' in response['address']:
|
||||
city = response['address']['city']
|
||||
if 'country_code' in response['address']:
|
||||
country = response['address']['country_code']
|
||||
with open(_data_path, 'r') as f:
|
||||
for line_number, line in enumerate(f):
|
||||
fields = line.split('\t')
|
||||
file_city_name = fields[2]
|
||||
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)
|
||||
|
||||
@staticmethod
|
||||
|
|
Loading…
Reference in New Issue
Block a user