Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. def haversine(lon1, lat1, lon2, lat2):
  2. """
  3. Calculate the great circle distance between two points
  4. on earth (specified in decimal degrees)
  5. """
  6. # convert decimal degrees to radians
  7. lat1 = radians(lat1)
  8. lon1 = radians(lon1)
  9. lat2 = radians(lat2)
  10. lon2 = radians(lon2)
  11. # haversine formula
  12. dlon = lon2 - lon1
  13. dlat = lat2 - lat1
  14. a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
  15. c = 2 * asin(sqrt(a))
  16. r = 6371 # Radius of earth in kilometers. Use 3956 for miles
  17. distance_btwn_points= c * r
  18. return distance_btwn_points
  19.  
  20. radius = 2.00 # in kilometer
  21. ship_navigation_port=ship_navigation.copy()
  22. ship_navigation_port['port_id']= 0
  23. for port in ports_location['port_id']:
  24. for index, row in ship_navigation_port.iterrows():
  25. ship_navigation_port['port_id']= np.where(haversine( ports_location['lon'][port], ports_location['lat'][port], row['lon'], row['lat'])<= radius, ports_location['port_id'][port], 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement