-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeoPoint.py
More file actions
49 lines (35 loc) · 1.42 KB
/
Copy pathGeoPoint.py
File metadata and controls
49 lines (35 loc) · 1.42 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
40
41
42
43
44
45
46
47
48
49
#GeoPoint.py
#Programmer: A. Seun Ajayi
#Email: aajayi@cnm.edu
#Purpose: create a GeoPoint class
import math
#create class
class GeoPoint:
def __init__(self,lat=0, lon=0,description='TBD'):
self.lat = lat
self.lon = lon
self.description = description
#string method to print object
def __str__(self):
return f"You are closest to {self.description} which is located at ({self.lat:.2f},{self.lon:.2f})"
def GetPoint(self):
return self.lat, self.lon
#tuple variable to set the lat and lon
def SetPoint(self, Pcoordinate):
self.lat, self.lon = Pcoordinate
#property to call the setter and getter methods
Pcoordinate = property(GetPoint, SetPoint)
def SetDescription(self, descP):
self.description = descP
def GetDescription(self):
return self.description
#property to set and get the description method
descP = property(GetDescription,SetDescription)
#Calculates distance
def Distance(self, toPoint):
userPoint = toPoint.Pcoordinate
a = math.sin((self.lat-userPoint[0])/2) * math.sin((self.lat-userPoint[0])/2) \
+ math.cos(self.lat) * math.cos(userPoint[0]) * (math.sin((self.lon-userPoint[1])/2) * math.sin((self.lon-userPoint[1])/2))
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a))
d = 6371.0 * c
return d