From 36ab891f44fd6e3b894da079d6560de630747e28 Mon Sep 17 00:00:00 2001 From: Sven Czarnian Date: Tue, 12 Oct 2021 22:26:05 +0200 Subject: [PATCH] switch to geod-library --- aman/types/Waypoint.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/aman/types/Waypoint.py b/aman/types/Waypoint.py index 040d8e9..38aadc4 100644 --- a/aman/types/Waypoint.py +++ b/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