-
Notifications
You must be signed in to change notification settings - Fork 0
/
navaidsreader.py
65 lines (44 loc) · 2.11 KB
/
navaidsreader.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
# This file parses the vasFMC format Navaids.txt file
# Navaids.txt file must be in AIRAC directory
from objects import PointInSpace
from objects import AmbiguousPoint
from objects import Coordinates
def navaid_dict_maker():
navaid_file = open("AIRAC/Navaids.txt")
navaid_dict = {}
for line in navaid_file:
currentline = line.rstrip().split("|")
navaidid = currentline[0]
navaidname = currentline[1]
navaidlat = currentline[6]
navaidlong = currentline[7]
navaidlatisnegative = False # establish variable
if navaidlat.startswith("-"):
navaidlatisnegative = True
navaidlat = navaidlat[1:]
if len(navaidlat) < 7:
navaidlat = "0" * (7 - len(navaidlat)) + navaidlat
navaidlatwithdecimal = navaidlat[:-6] + "." + navaidlat[-6:] # 6 decimal places
if navaidlatisnegative is True:
navaidlatwithdecimal = "-" + navaidlatwithdecimal
navaidlongisnegative = False # establish variable
if navaidlong.startswith("-"):
navaidlongisnegative = True
navaidlong = navaidlong[1:]
if len(navaidlong) < 7:
navaidlong = "0" * (7 - len(navaidlong)) + navaidlong
navaidlongwithdecimal = navaidlong[:-6] + "." + navaidlong[-6:] # 6 decimal places
if navaidlongisnegative is True:
navaidlongwithdecimal = "-" + navaidlongwithdecimal
navaidcoordinates = Coordinates(navaidlatwithdecimal, navaidlongwithdecimal)
navaidobj = PointInSpace(navaidid, navaidcoordinates, 'NAVAID', navaidname)
if navaidid in navaid_dict:
if type(navaid_dict[navaidid]) is AmbiguousPoint:
navaid_dict[navaidid].add_possibility(navaidobj)
else:
navaid_dict[navaidid] = AmbiguousPoint(navaidid, navaid_dict[navaidid])
navaid_dict[navaidid].add_possibility(navaidobj)
else:
navaid_dict[navaidid] = navaidobj
navaid_file.close()
return navaid_dict