Files
aman-sys/aman/types/Waypoint.py
2021-10-13 12:52:29 +02:00

39 lines
1.3 KiB
Python

#!/usr/bin/env python
import numpy as np
import pyproj
class Waypoint:
def dms2dd(coordinate : str):
split = coordinate.split('.')
if 4 != len(split):
return 0.0
direction = split[0][1]
degrees = float(split[0][1:])
minutes = float(split[1])
seconds = float(split[2]) * (float(split[3]) / 1000.0)
dd = degrees + minutes / 60.0 + seconds / (60 * 60)
if 'E' == direction or 'S' == direction:
dd *= -1.0
return dd
def __init__(self, name : str, latitude : float, longitude : float):
self.Name = name
self.Coordinate = np.array([ latitude, longitude ])
def __str__(self):
return 'Name: ' + self.Name + ', Lat: ' + str(self.Coordinate[0]) + ', Lon: ' + str(self.Coordinate[1])
def haversine(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 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