reverse geocoder

pull/1054/head
Harald Schafer 2020-02-04 13:44:37 -08:00
parent 9c5e035838
commit bc725b98c9
3 changed files with 144586 additions and 0 deletions

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,21 @@
import numpy as np
import os
import csv
path = os.path.dirname(os.path.abspath(__file__))
csv_file_name = path + '/rg_cities1000.csv'
# right hand drive is the same as left hand traffic
LHT_COUNTRIES = ['AU', 'IN', 'IE', 'JP', 'MU', 'MY', 'NZ', 'UK', 'ZA']
def get_city(lat, lon):
cities = np.array(list(csv.reader(open(csv_file_name))))[1:]
positions = cities[:,:2].astype(np.float32)
idx = np.argmin(np.linalg.norm((positions - np.array([lat, lon])), axis=1))
return cities[idx]
def is_lht(lat, lon):
city = get_city(lat, lon)
country = city[-1]
return country in LHT_COUNTRIES

File diff suppressed because it is too large Load Diff