-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
158 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import re | ||
from pathlib import Path | ||
|
||
from mapbuilder.utils import geo | ||
from mapbuilder.utils.legacy import parse_es_coords | ||
|
||
|
||
def parse_airport(file_path: Path) -> dict: | ||
"""Parses Runway information from the SCT""" | ||
pattern = r"^(\w{4})\s+(\d{3}\.\d{3})\s+(\S+)\s+(\S+)\s+(\w)$" | ||
|
||
ads = {} | ||
in_section = False | ||
|
||
with file_path.open("r", encoding="iso-8859-1") as f: | ||
for raw_line in f: | ||
line = raw_line.strip() | ||
if line.startswith(";"): | ||
continue | ||
|
||
if line == "[AIRPORT]": | ||
in_section = True | ||
continue | ||
|
||
if not in_section: | ||
continue | ||
|
||
# Next section | ||
if line.startswith("["): | ||
break | ||
|
||
match = re.search(pattern, line) | ||
|
||
if match: | ||
ads[match.group(1)] = geo.Fix( | ||
parse_es_coords(match.group(3), match.group(4)) | ||
) | ||
|
||
return ads | ||
|
||
|
||
def parse_runway(file_path: Path) -> dict: | ||
"""Parses Runway information from the SCT""" | ||
pattern = r"^(\d{2}[LRC]?)\s+(\d{2}[LRC]?)\s+(\d{3})\s+(\d{3})\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\w{4})$" | ||
|
||
ads = parse_airport(file_path) | ||
runways = {} | ||
in_section = False | ||
|
||
with file_path.open("r", encoding="iso-8859-1") as f: | ||
for raw_line in f: | ||
line = raw_line.strip() | ||
if line.startswith(";"): | ||
continue | ||
|
||
if line == "[RUNWAY]": | ||
in_section = True | ||
continue | ||
|
||
if not in_section: | ||
continue | ||
|
||
# Next section | ||
if line.startswith("["): | ||
break | ||
|
||
match = re.search(pattern, line) | ||
|
||
if match: | ||
rwy1 = match.group(1) | ||
rwy2 = match.group(2) | ||
rwystr = f"{rwy1}-{rwy2}" | ||
icao = match.group(9) | ||
thr1 = geo.Fix(parse_es_coords(match.group(5), match.group(6))) | ||
thr2 = geo.Fix(parse_es_coords(match.group(7), match.group(8))) | ||
|
||
if icao not in runways: | ||
runways[icao] = {} | ||
|
||
runways[icao][rwystr] = { | ||
"rwy1": rwy1, | ||
"rwy2": rwy2, | ||
"brg1": int(match.group(3)), | ||
"brg2": int(match.group(4)), | ||
"thr1": thr1, | ||
"thr2": thr2, | ||
"center": ads[icao], | ||
} | ||
|
||
return runways |
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,24 @@ | ||
def render_runways(ad: dict, length: float = 1.5, exclude: list | None = None) -> str: | ||
if exclude is None: | ||
exclude = [] | ||
lines = [] | ||
|
||
for rwy_id, data in ad.items(): | ||
if rwy_id in exclude: | ||
continue | ||
|
||
if data["brg1"] == 0 and data["brg2"] == 0: | ||
continue | ||
|
||
lines.append(str(data["center"].move_to(length / 2, data["brg2"]).line_to(length, data["brg1"]))) | ||
|
||
return "\n".join(lines) | ||
|
||
|
||
def render_cl(ad: dict) -> str: | ||
lines = [] | ||
|
||
for _, data in ad.items(): | ||
lines.append(str(data["thr1"].line_to_fix(data["thr2"]))) | ||
|
||
return "\n".join(lines) |
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,21 @@ | ||
def parse_es_coords(lat_str, lon_str): | ||
def convert_to_decimal(degree, minute, second, direction): | ||
decimal = degree + minute / 60 + second / 3600 | ||
if direction in ["S", "W"]: | ||
decimal = -decimal | ||
return decimal | ||
|
||
lat_deg = int(lat_str[1:4]) | ||
lat_min = int(lat_str[5:7]) | ||
lat_sec = float(lat_str[8:13]) | ||
lat_dir = lat_str[0] | ||
|
||
lon_deg = int(lon_str[1:4]) | ||
lon_min = int(lon_str[5:7]) | ||
lon_sec = float(lon_str[8:13]) | ||
lon_dir = lon_str[0] | ||
|
||
latitude = convert_to_decimal(lat_deg, lat_min, lat_sec, lat_dir) | ||
longitude = convert_to_decimal(lon_deg, lon_min, lon_sec, lon_dir) | ||
|
||
return latitude, longitude |