Browse Source

switch to geod-library

Sven Czarnian 3 years ago
parent
commit
36ab891f44
1 changed files with 9 additions and 4 deletions
  1. 9 4
      aman/types/Waypoint.py

+ 9 - 4
aman/types/Waypoint.py

@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 
-from sklearn.metrics.pairwise import haversine_distances
 import numpy as np
+import pyproj
 
 class Waypoint:
     def dms2dd(coordinate : str):
@@ -28,6 +28,11 @@ class Waypoint:
         return 'Name: ' + self.name + ', Lat: ' + str(self.coordinate[0]) + ', Lon: ' + str(self.coordinate[1])
 
     def haversine(self, other):
-        self_radians = [np.radians(_) for _ in self.coordinate]
-        other_radians = [np.radians(_) for _ in other.coordinate]
-        return 6371.0 * haversine_distances([self_radians, other_radians])[0][1]
+        geodesic = pyproj.Geod(ellps='WGS84')
+        forward, backward, distance = geodesic.inv(self.coordinate[1], self.coordinate[0], other.coordinate[1], other.coordinate[0])
+        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