Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def haversine(lon1, lat1, lon2, lat2):
- """
- Calculate the great circle distance between two points
- on earth (specified in decimal degrees)
- """
- # convert decimal degrees to radians
- lat1 = radians(lat1)
- lon1 = radians(lon1)
- lat2 = radians(lat2)
- lon2 = radians(lon2)
- # haversine formula
- dlon = lon2 - lon1
- dlat = lat2 - lat1
- a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
- c = 2 * asin(sqrt(a))
- r = 6371 # Radius of earth in kilometers. Use 3956 for miles
- distance_btwn_points= c * r
- return distance_btwn_points
- radius = 2.00 # in kilometer
- ship_navigation_port=ship_navigation.copy()
- ship_navigation_port['port_id']= 0
- for port in ports_location['port_id']:
- for index, row in ship_navigation_port.iterrows():
- 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