|
40 | 40 | def kaganCalc(x): |
41 | 41 | return modules.kagan.get_kagan_angle(*x[0:3], *x[3:6]) |
42 | 42 |
|
43 | | -def cart2earth(lat,lon,x,y): |
| 43 | +def cart2earth(lat, lon, x, y): |
44 | 44 | """ |
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. |
50 | 46 | """ |
51 | 47 | 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 | | - ''' |
59 | 48 | EARTH_MEAN_RADIUS = 6371008.8 |
60 | | - |
61 | 49 | lon1, lat1 = (math.radians(coord) for coord in point) |
62 | 50 | radians_bearing = math.radians(bearing) |
63 | | - |
64 | 51 | delta = distance / EARTH_MEAN_RADIUS |
65 | | - |
66 | 52 | lat2 = math.asin( |
67 | 53 | math.sin(lat1)*math.cos(delta) + |
68 | 54 | math.cos(lat1)*math.sin(delta)*math.cos(radians_bearing) |
69 | 55 | ) |
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 | + ) |
75 | 60 | lon2_deg = (math.degrees(lon2) + 540) % 360 - 180 |
76 | 61 | lat2_deg = math.degrees(lat2) |
77 | | - |
78 | 62 | return (lon2_deg, lat2_deg) |
79 | 63 |
|
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 |
97 | 68 |
|
| 69 | + lon2, lat2 = destination((lon, lat), dist, azm) |
| 70 | + return round(lat2, 4), round(lon2, 4) |
98 | 71 |
|
99 | 72 | def calculateVariance(observed, synthetic, tl): |
100 | 73 | """ |
|
0 commit comments