This repository was archived by the owner on Sep 11, 2025. It is now read-only.
forked from marcin-osowski/igc_lib
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTakeOffLocationService.py
More file actions
45 lines (34 loc) · 1.53 KB
/
Copy pathTakeOffLocationService.py
File metadata and controls
45 lines (34 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from injectable import injectable
import geojson as geojson
from py_linq import Enumerable
from shapely.geometry import Point
from igc_lib import Flight
@injectable
class TakeOffLocationService:
""" Enrich flight with Take off location"""
@property
def geojson_airports(self) -> dict:
return self._geojson_airports
# geojson_airports: dict
def __init__(self):
self._geojson_airports = self.get_airports()
def get_airports(self, airport_file_location: str = None) -> dict:
with open("./geojson/openaip-airport.geojson") as f:
data = geojson.load(f)
return data
def get_takeoff_location_lat_lon(self, lat, lon) -> str:
airports = Enumerable(self._geojson_airports.features)
# Find nearest airport using distance.
# 0.01 degree = 1.11 Km See: https://www.usna.edu/Users/oceano/pguth/md_help/html/approx_equivalents.htm
filtered_airports = airports.where(
lambda f: Point(lon, lat).distance(
Point(f.geometry.coordinates)) <= 0.01).to_list()
if Enumerable(filtered_airports).any():
return filtered_airports[0].properties["icao"]
return None
def get_takeoff_location_for_flight(self, flight: Flight) -> Flight:
flight_takeoff = flight.takeoff_fix
found_takeoff_location = self.get_takeoff_location_lat_lon(flight_takeoff.lat, flight_takeoff.lon)
if found_takeoff_location is not None:
flight.takeoff_location = found_takeoff_location
return flight