-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeojson_parser.py
73 lines (58 loc) · 2.46 KB
/
geojson_parser.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import json
import numpy as np
def read_file(path: str) -> dict:
sector = None
terminal_control_zones = {}
vertiports = {}
frzs = {}
with open(path) as file:
data = json.load(file)
for item in data.get("features", []):
name = item["properties"]["name"]
geom = item["geometry"]
_type = geom["type"]
coordinates = np.array(geom["coordinates"])
if name.lower() == "airspace":
if sector is not None:
raise ValueError("Sector area already exists. Multiple sector areas cannot exist.")
sector = coordinates[0]
elif geom["type"].lower() == "point":
if name in vertiports:
raise IndexError(
f"A vertiport with name {name} already exists. Multiple vertiports with the same"
+ "name cannot exist."
)
vertiports[name] = coordinates
elif name.startswith("TCZ_"):
if name in terminal_control_zones:
raise IndexError(
f"A TCZ with name {name} already exists. Multiple TCZs with the same name cannot exist."
)
if _type == "LineString":
terminal_control_zones[name] = coordinates
else:
terminal_control_zones[name] = coordinates[0]
elif name.startswith("FRZ_") or name.startswith("NFZ_"):
if name in frzs:
raise IndexError(
f"A FRZ with name {name} already exists. Multiple FRZs with the same name cannot exist."
)
frzs[name] = coordinates[0]
if sector is None:
raise ValueError("A sector does not exist. A sector must exist and have valid bounds.")
if not vertiports:
raise ValueError("No vertiports found. Vertiports must exist")
min_bounds = sector.min(axis=0)
min_bounds[2] = 0
max_bounds = sector.max(axis=0)
for tcz in terminal_control_zones:
terminal_control_zones[tcz] = np.clip(terminal_control_zones[tcz], min_bounds, max_bounds)
for frz in frzs:
frzs[frz] = np.clip(frzs[frz], min_bounds, max_bounds)
return {
"sector": sector,
"vertiports": vertiports,
"TCZs": terminal_control_zones,
"FRZs": frzs,
}
# print(read_file('airspaces/NYC+Zones.geojson'))