alteryx / alteryx/featuretools
Add Bearing primitive
- Dominant language
- Python
- Stars
- 7.7k
- Forks
- 915
- PR merge metrics
- No merged PRs in 30d
Description
> In navigation, bearing is the horizontal angle between the direction of an object and another object, or between it and that of true north.
- We use this primitive in the NYC taxi trip problem
- https://github.com/alteryx/open_source_demos/blob/main/predict-taxi-trip-duration/NYC%20Taxi%204%20-%20Custom%20Featuretools%20Primitives.ipynb
```python
def bearing(latlong1, latlong2):
lat1 = np.array([x[0] for x in latlong1])
lon1 = np.array([x[1] for x in latlong1])
lat2 = np.array([x[0] for x in latlong2])
lon2 = np.array([x[1] for x in latlong2])
delta_lon = np.radians(lon2 - lon1)
lon1, lat1, lon2, lat2 = map(np.radians, [lon1, lat1, lon2, lat2])
x = np.cos(lat2) * np.sin(delta_lon)
y = np.cos(lat1) * np.sin(lat2) - np.sin(lat1) * np.cos(lat2) * np.cos(delta_lon)
return np.degrees(np.arctan2(x, y))
```
Contributor guide
Assessment
This issue has not been assessed yet.