-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalisation.py
More file actions
39 lines (30 loc) · 1.12 KB
/
Localisation.py
File metadata and controls
39 lines (30 loc) · 1.12 KB
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
from geopy.geocoders import Nominatim
class Localisation:
def __init__(self, latitude=0, longitude=0):
self.lat = latitude
self.lon = longitude
def from_DD(self, latitude, longitude):
self.lat = latitude
self.lon = longitude
def from_DMS(self, degreN, minN, secN, degreE, minE, secE):
self.lat = degreN + minN / 60 + secN / 3600
self.lon = degreE + minE / 60 + secE / 3600
def from_adress(self, adress):
try:
geocoder = Nominatim(user_agent="myGeocoder")
loc = geocoder.geocode(adress)
self.lat = loc.latitude
self.lon = loc.longitude
return True
except:
print("Adresse incorrecte : " + adress)
return False
def to_tuple(self):
return self.lat, self.lon
def to_string(self):
return "({lat}, {lon})".format(lat=self.lat, lon=self.lon)
def to_url(self):
return "{lat},{lon}".format(lat=self.lat, lon=self.lon)
def display(self):
print("Latitude : {lat}".format(lat=self.lat))
print("Longitude : {lon}".format(lon=self.lon))