Skip to content

Commit 86b5885

Browse files
committed
Fix cart2earth issue
1 parent 4496f2a commit 86b5885

File tree

1 file changed

+12
-39
lines changed

1 file changed

+12
-39
lines changed

src/isola.py

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -40,61 +40,34 @@
4040
def kaganCalc(x):
4141
return modules.kagan.get_kagan_angle(*x[0:3], *x[3:6])
4242

43-
def cart2earth(lat,lon,x,y):
43+
def cart2earth(lat, lon, x, y):
4444
"""
45-
BSD 3-Clause License
46-
Copyright (c) 2017, Juno Inc.
47-
All rights reserved.
48-
https://github.com/gojuno/geo-py/blob/master/geo/sphere.py
49-
Calculate lat and lon from origin lat lon and cart position
45+
Calculate destination latitude and longitude given a local Cartesian displacement (x east, y north) in km.
5046
"""
5147
def destination(point, distance, bearing):
52-
'''
53-
Given a start point, initial bearing, and distance, this will
54-
calculate the destina?tion point and final bearing travelling
55-
along a (shortest distance) great circle arc.
56-
57-
(see http://www.movable-type.co.uk/scripts/latlong.htm)
58-
'''
5948
EARTH_MEAN_RADIUS = 6371008.8
60-
6149
lon1, lat1 = (math.radians(coord) for coord in point)
6250
radians_bearing = math.radians(bearing)
63-
6451
delta = distance / EARTH_MEAN_RADIUS
65-
6652
lat2 = math.asin(
6753
math.sin(lat1)*math.cos(delta) +
6854
math.cos(lat1)*math.sin(delta)*math.cos(radians_bearing)
6955
)
70-
numerator = math.sin(radians_bearing) * math.sin(delta) * math.cos(lat1)
71-
denominator = math.cos(delta) - math.sin(lat1) * math.sin(lat2)
72-
73-
lon2 = lon1 + math.atan2(numerator, denominator)
74-
56+
lon2 = lon1 + math.atan2(
57+
math.sin(radians_bearing)*math.sin(delta)*math.cos(lat1),
58+
math.cos(delta) - math.sin(lat1)*math.sin(lat2)
59+
)
7560
lon2_deg = (math.degrees(lon2) + 540) % 360 - 180
7661
lat2_deg = math.degrees(lat2)
77-
7862
return (lon2_deg, lat2_deg)
7963

80-
dist=math.sqrt(x**2+y**2)*1000
81-
try:
82-
if x==0 and y==0:
83-
azm=0
84-
elif y>=0 and x>=0:
85-
azm=math.atan(x/y)
86-
elif y<0 and x>=0:
87-
azm=180-math.atan(x/abs(y))
88-
elif y<=0 and x<=0:
89-
azm=180+math.atan(abs(x)/abs(y))
90-
elif y>0 and x<0:
91-
azm=270+math.atan(abs(y)/abs(x))
92-
except ZeroDivisionError:
93-
azm=90 if x>0 else -90
94-
95-
lon2,lat2=destination((lon,lat), dist, azm)
96-
return round(lat2, 4), round(lon2, 4)
64+
dist = math.sqrt(x**2 + y**2) * 1000 # meters
65+
azm = math.degrees(math.atan2(x, y))
66+
if azm < 0:
67+
azm += 360
9768

69+
lon2, lat2 = destination((lon, lat), dist, azm)
70+
return round(lat2, 4), round(lon2, 4)
9871

9972
def calculateVariance(observed, synthetic, tl):
10073
"""

0 commit comments

Comments
 (0)