switch to geod-library
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from sklearn.metrics.pairwise import haversine_distances
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import pyproj
|
||||||
|
|
||||||
class Waypoint:
|
class Waypoint:
|
||||||
def dms2dd(coordinate : str):
|
def dms2dd(coordinate : str):
|
||||||
@@ -28,6 +28,11 @@ class Waypoint:
|
|||||||
return 'Name: ' + self.name + ', Lat: ' + str(self.coordinate[0]) + ', Lon: ' + str(self.coordinate[1])
|
return 'Name: ' + self.name + ', Lat: ' + str(self.coordinate[0]) + ', Lon: ' + str(self.coordinate[1])
|
||||||
|
|
||||||
def haversine(self, other):
|
def haversine(self, other):
|
||||||
self_radians = [np.radians(_) for _ in self.coordinate]
|
geodesic = pyproj.Geod(ellps='WGS84')
|
||||||
other_radians = [np.radians(_) for _ in other.coordinate]
|
forward, backward, distance = geodesic.inv(self.coordinate[1], self.coordinate[0], other.coordinate[1], other.coordinate[0])
|
||||||
return 6371.0 * haversine_distances([self_radians, other_radians])[0][1]
|
return distance / 1000.0
|
||||||
|
|
||||||
|
def bearing(self, other):
|
||||||
|
geodesic = pyproj.Geod(ellps='WGS84')
|
||||||
|
forward, backward, distance = geodesic.inv(self.coordinate[1], self.coordinate[0], other.coordinate[1], other.coordinate[0])
|
||||||
|
return forward
|
||||||
|
|||||||
Reference in New Issue
Block a user