-
Notifications
You must be signed in to change notification settings - Fork 2
/
flogger_get_coords.py
64 lines (62 loc) · 2.79 KB
/
flogger_get_coords.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#
# Function to determine latitude, longitude and elevation given location place name details.
# Details are returned as a list.
# For example if called as:
# loc = get_coords("My Gliding Club UK")
# then:
# latitude = loc[0], longitude = loc[1], elevation = loc[2]
#
#
from geopy.geocoders import Nominatim
import geocoder
from geopy.exc import GeocoderTimedOut
import time
from geopy.geocoders.base import ERROR_CODE_MAP
import geopy
def get_coords(address):
try:
geolocator = Nominatim(user_agent="OGN_Flogger")
try:
location = geolocator.geocode(address, timeout=5, exactly_one=True) # Only 1 location for this address
if location == None:
print "Geocoder Service timed out or Airfield: ", address, " not known by geocode locator service. Check settings"
return False
i = 1
while i <= 10:
ele = geocoder.google([location.latitude, location.longitude], method='elevation')
if ele.meters == None:
print "geocoder.google try: ", i
i = i + 1
time.sleep(1)
continue
else:
print "Geolocator worked for: ", address, " Lat: ", location.latitude, " Long: ", location.longitude, " Ele: ",ele.meters
return location.latitude, location.longitude, ele.meters
print "Geolocator failed for: ", address, " Lat: ", location.latitude, " Long: ", location.longitude, " Ele: ", ele.meters, "Try a Restart"
exit(2)
except ERROR_CODE_MAP[400]:
print " ERROR_CODE_MAP is: ", ERROR_CODE_MAP[400]
except ERROR_CODE_MAP[401]:
print " ERROR_CODE_MAP is: ", ERROR_CODE_MAP[401]
except ERROR_CODE_MAP[402]:
print " ERROR_CODE_MAP is: ", ERROR_CODE_MAP[402]
except ERROR_CODE_MAP[403]:
print " ERROR_CODE_MAP is: ", ERROR_CODE_MAP[403]
except ERROR_CODE_MAP[407]:
print " ERROR_CODE_MAP is: ", ERROR_CODE_MAP[407]
except ERROR_CODE_MAP[412]:
print " ERROR_CODE_MAP is: ", ERROR_CODE_MAP[412]
except ERROR_CODE_MAP[413]:
print " ERROR_CODE_MAP is: ", ERROR_CODE_MAP[413]
except ERROR_CODE_MAP[414]:
print " ERROR_CODE_MAP is: ", ERROR_CODE_MAP[414]
except ERROR_CODE_MAP[502]:
print " ERROR_CODE_MAP is: ", ERROR_CODE_MAP[502]
except ERROR_CODE_MAP[503]:
print " ERROR_CODE_MAP is: ", ERROR_CODE_MAP[503]
except ERROR_CODE_MAP[504]:
print " ERROR_CODE_MAP is: ", ERROR_CODE_MAP[503]
return False
except GeocoderTimedOut as e:
print "Geocoder Service timed out for Airfield: ", address
return False