kopia lustrzana https://github.com/glidernet/ogn-python
utils: Remove unused wgs84_to_sphere
Use an external package[1] instead. [1]: eg. https://pypi.python.org/pypi/haversinepull/26/head
rodzic
7fb4763422
commit
d5dc94903d
14
ogn/utils.py
14
ogn/utils.py
|
@ -1,7 +1,6 @@
|
||||||
import requests
|
import requests
|
||||||
import csv
|
import csv
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from math import sin, cos, asin, atan2, sqrt, pi
|
|
||||||
|
|
||||||
from .model import Device, AddressOrigin
|
from .model import Device, AddressOrigin
|
||||||
|
|
||||||
|
@ -9,8 +8,6 @@ from geopy.geocoders import Nominatim
|
||||||
|
|
||||||
DDB_URL = "http://ddb.glidernet.org/download"
|
DDB_URL = "http://ddb.glidernet.org/download"
|
||||||
|
|
||||||
deg2rad = pi/180
|
|
||||||
rad2deg = 1/deg2rad
|
|
||||||
|
|
||||||
address_prefixes = {'F':'FLR',
|
address_prefixes = {'F':'FLR',
|
||||||
'O':'OGN',
|
'O':'OGN',
|
||||||
|
@ -63,14 +60,3 @@ def get_country_code(latitude, longitude):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
country_code = None
|
country_code = None
|
||||||
return country_code
|
return country_code
|
||||||
|
|
||||||
|
|
||||||
def wgs84_to_sphere(lat1, lat2, lon1, lon2, alt1, alt2):
|
|
||||||
lat1 = lat1*deg2rad
|
|
||||||
lat2 = lat2*deg2rad
|
|
||||||
lon1 = lon1*deg2rad
|
|
||||||
lon2 = lon2*deg2rad
|
|
||||||
radius = 6366000*2*asin(sqrt((sin((lat1-lat2)/2))**2 + cos(lat1)*cos(lat2)*(sin((lon1-lon2)/2))**2))
|
|
||||||
theta = atan2(alt2-alt1, radius)*rad2deg
|
|
||||||
phi = atan2(sin(lon2-lon1)*cos(lat2), cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(lon2-lon1))*rad2deg
|
|
||||||
return radius, theta, phi
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from ogn.utils import get_ddb, get_trackable, get_country_code, wgs84_to_sphere
|
from ogn.utils import get_ddb, get_trackable, get_country_code
|
||||||
from ogn.model import AddressOrigin
|
from ogn.model import AddressOrigin
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,19 +43,3 @@ class TestStringMethods(unittest.TestCase):
|
||||||
longitude = -0.0009119
|
longitude = -0.0009119
|
||||||
country_code = get_country_code(latitude, longitude)
|
country_code = get_country_code(latitude, longitude)
|
||||||
self.assertEqual(country_code, None)
|
self.assertEqual(country_code, None)
|
||||||
|
|
||||||
def test_wgs84_to_sphere(self):
|
|
||||||
# receiver
|
|
||||||
lat1 = 48.865
|
|
||||||
lon1 = 9.2225
|
|
||||||
alt1 = 574
|
|
||||||
|
|
||||||
# aircraft beacon
|
|
||||||
lat2 = 48.74435
|
|
||||||
lon2 = 9.578
|
|
||||||
alt2 = 929
|
|
||||||
|
|
||||||
[radius, theta, phi] = wgs84_to_sphere(lat1, lat2, lon1, lon2, alt1, alt2)
|
|
||||||
self.assertAlmostEqual(radius, 29265.6035812215, 5)
|
|
||||||
self.assertAlmostEqual(theta, 0.694979846308314, 5)
|
|
||||||
self.assertAlmostEqual(phi, 117.1275408121, 5)
|
|
||||||
|
|
Ładowanie…
Reference in New Issue