-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from flightaware/proxy-map-request
Add endpoint that returns flight map image
- Loading branch information
Showing
5 changed files
with
105 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ sqlalchemy==1.3.16 | |
Flask==1.1.2 | ||
flask-cors==3.0.9 | ||
psycopg2-binary==2.8.5 | ||
requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from math import degrees, radians, sin, cos, atan2 | ||
from typing import Tuple | ||
|
||
|
||
def get_bearing_degrees(coord1: Tuple[float, float], coord2: Tuple[float, float]) -> float: | ||
"""Get bearing in degrees between 2 sets of coordinates""" | ||
r_lat1 = radians(coord1[0]) | ||
r_lon1 = radians(coord1[1]) | ||
r_lat2 = radians(coord2[0]) | ||
r_lon2 = radians(coord2[1]) | ||
d_lon = r_lon2 - r_lon1 | ||
y = sin(d_lon) * cos(r_lat2) | ||
x = cos(r_lat1) * sin(r_lat2) - sin(r_lat1) * cos(r_lat2) * cos(d_lon) | ||
bearing = degrees(atan2(y, x)) | ||
bearing = (bearing + 360) % 360 | ||
return bearing | ||
|
||
|
||
def get_cardinal_for_angle(angle_degrees: float) -> int: | ||
"""Approximate an angle in degrees to 1 of 4 cardinal directions""" | ||
if 45 <= angle_degrees < 135: | ||
return 90 | ||
elif 135 <= angle_degrees < 225: | ||
return 180 | ||
elif 225 <= angle_degrees < 315: | ||
return 270 | ||
else: | ||
return 0 |