-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfir_uir_info.py
More file actions
55 lines (50 loc) · 1.91 KB
/
fir_uir_info.py
File metadata and controls
55 lines (50 loc) · 1.91 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
46
47
48
49
50
51
52
53
54
55
import json
import logging
import shapely
import time
from shapely import speedups
if speedups.available:
speedups.enable()
from shapely.geometry import shape, Point
logger = logging.getLogger(__name__)
# load GeoJSON file containing sectors
with open('static/flightmap_europe_fir_uir.json') as f:
firuirs = json.load(f)
def get_fir_uir_by_position(latitude, longitude, flight_level=0):
# construct point based on lon/lat of aircraft position
point = Point(longitude, latitude)
# check each polygon to see if it contains the point
for feature in firuirs['features']:
if feature['properties']['MAX_FLIGHT'] < flight_level:
# altitude too high for this airspace
continue
elif feature['properties']['MIN_FLIGHT'] == 0:
# altitude cannot be too low for this airspace
pass
elif feature['properties']['MIN_FLIGHT'] > flight_level:
# altitude too low for this airspace
continue
minx, miny, maxx, maxy = feature['bbox']
if not (maxy >= latitude >= miny and
maxx >= longitude >= minx):
continue
polygon = shape(feature['geometry'])
if feature['geometry']['type'] == 'MultiPolygon':
# If the FIR consists of multiple polygons we need to iterate over
# each single polygon.
multipolygon = polygon
for polygon in multipolygon:
if polygon.contains(point):
return feature['properties']
elif polygon.contains(point):
return feature['properties']
logging.debug('No FIR found at ({}, {}).'.format(latitude, longitude))
if __name__ == '__main__':
latitude = 52.
longitude = 7.3
flight_level = 244.9+0.1
t_start = time.time()
data = get_fir_uir_by_position(latitude, longitude, flight_level)
t_stop = time.time()
print (t_stop - t_start)
print (data)