Waypoint.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env python
  2. from sklearn.metrics.pairwise import haversine_distances
  3. import numpy as np
  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. self_radians = [np.radians(_) for _ in self.coordinate]
  24. other_radians = [np.radians(_) for _ in other.coordinate]
  25. return 6371.0 * haversine_distances([self_radians, other_radians])[0][1]