• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Aug 21st, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import numpy as np
2. from numpy import pi, deg2rad, cos, sin, arcsin, sqrt
3.
4. def haversine(s_lat, s_lng, e_lat, e_lng):
5.     """
6.     determines the great-circle distance between two point
7.     on a sphere given their longitudes and latitudes
8.     """
9.
10.     # approximate radius of earth in miles
11.     R = 3959.87433
12.
13.     s_lat = s_lat * np.pi / 180.0
14.     s_lng = np.deg2rad(s_lng)
15.     e_lat = np.deg2rad(e_lat)
16.     e_lng = np.deg2rad(e_lng)
17.
18.     d = (
19.         np.sin((e_lat - s_lat) / 2) ** 2
20.         + np.cos(s_lat) * np.cos(e_lat) * np.sin((e_lng - s_lng) / 2) ** 2
21.     )
22.
23.     return 2 * R * np.arcsin(np.sqrt(d))
24.
25.
26. df['distance'] = haversine(
27.     df["start_lat"].values,
28.     df["start_long"].values,
29.     df["end_lat"].values,
30.     df["end_long"].values
31. )
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top