-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeo.py
More file actions
43 lines (32 loc) · 1.22 KB
/
Copy pathgeo.py
File metadata and controls
43 lines (32 loc) · 1.22 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
print "Loaded geo class..."
import math
from decimal import Decimal
class Geo:
@staticmethod
def boundingBox(location, radius_km):
deg2rad = math.radians
rad2deg = math.degrees
radDist = radius_km / 6371.0
radLat = deg2rad(location['lat'])
radLon = deg2rad(location['lon'])
minLat = radLat - radDist
maxLat = radLat + radDist
deltaLon = math.asin(math.sin(radDist) / math.cos(radLat))
minLon = radLon - deltaLon
maxLon = radLon + deltaLon
return dict(latMin=rad2deg(minLat), lonMin=rad2deg(minLon), latMax=rad2deg(maxLat), lonMax=rad2deg(maxLon))
# returns distance in between two loctaions
@staticmethod
def distance(location1, location2):
rad2deg = math.degrees
deg2rad = math.radians
lat1 = location1['lat']
lat2 = location2['lat']
lon1 = location1['lon']
lon2 = location2['lon']
theta = lon1 - lon2
dist = math.sin(deg2rad(lat1)) * math.sin(deg2rad(lat2)) + math.cos(deg2rad(lat1)) * math.cos(deg2rad(lat2)) * math.cos(deg2rad(theta));
dist = math.acos(dist);
dist = rad2deg(dist);
dist = dist * 60 * 1.852 * 1000;
return dist