a guest Dec 15th, 2018 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- def sphere_dist(pickup_lat, pickup_lon, dropoff_lat, dropoff_lon):
- Return distance along great radius between pickup and dropoff coordinates.
- #Define earth radius (km)
- R_earth = 6371
- #Convert degrees to radians
- pickup_lat, pickup_lon, dropoff_lat, dropoff_lon = map(np.radians, [pickup_lat, pickup_lon, dropoff_lat, dropoff_lon])
- #Compute distances along lat, lon dimensions
- dlat = dropoff_lat - pickup_lat
- dlon = dropoff_lon - pickup_lon
- #Compute haversine distance
- a = np.sin(dlat/2.0)**2 + np.cos(pickup_lat) * np.cos(dropoff_lat) * np.sin(dlon/2.0)**2
- return 2 * R_earth * np.arcsin(np.sqrt(a))
RAW Paste Data