Waypoint.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env python
  2. import numpy as np
  3. import pyproj
  4. class Waypoint:
  5. def dms2dd(coordinate : str):
  6. split = coordinate.split('.')
  7. if 4 != len(split):
  8. return 0.0
  9. direction = split[0][1]
  10. degrees = float(split[0][1:])
  11. minutes = float(split[1])
  12. seconds = float(split[2]) * (float(split[3]) / 1000.0)
  13. dd = degrees + minutes / 60.0 + seconds / (60 * 60)
  14. if 'E' == direction or 'S' == direction:
  15. dd *= -1.0
  16. return dd
  17. def __init__(self, name : str, latitude : float, longitude : float):
  18. self.name = name
  19. self.coordinate = np.array([ latitude, longitude ])
  20. def __str__(self):
  21. return 'Name: ' + self.name + ', Lat: ' + str(self.coordinate[0]) + ', Lon: ' + str(self.coordinate[1])
  22. def haversine(self, other):
  23. geodesic = pyproj.Geod(ellps='WGS84')
  24. forward, backward, distance = geodesic.inv(self.coordinate[1], self.coordinate[0], other.coordinate[1], other.coordinate[0])
  25. return distance / 1000.0
  26. def bearing(self, other):
  27. geodesic = pyproj.Geod(ellps='WGS84')
  28. forward, backward, distance = geodesic.inv(self.coordinate[1], self.coordinate[0], other.coordinate[1], other.coordinate[0])
  29. return forward