aerofiles.openair¶
- class aerofiles.openair.Reader(fp)¶
A higher-level reader for the OpenAir airspace file format:
with open('airspace.txt') as fp: reader = Reader(fp)
see OpenAir file format specification <https://github.com/naviter/seeyou_file_formats/blob/main/OpenAir_File_Format_Support.md>. It is able to handle standard and extended file format.
This class should be used as a generator and will return
(record, error)tuples for each airspace or terrain record:for record, error in reader: if error: raise error # or handle it otherwise # handle record
If there is a parsing error while reading a record the whole record is skipped and the parsing error will be returned from the generator. It is up to the calling code whether that parsing error should be handled as fatal or not.
Airspace records have the following structure:
{ "type": "airspace", "class": "C", "name": "Sacramento", "ident": "b3836bab-6bc3-48c1-b918-01c2559e26fa", "ground_name": "Sacramento Radio", "freq": "123.456", "airspace_type": "CTR", "floor": "500ft", "ceiling": "UNLIM", "activations": [ { "start": null, "end": null }, { "start": "2023-12-16T12:00Z", "end": "2023-12-16T13:00Z" }, { "start": "2024-12-17T00:00Z", "end": "2024-12-17T24:00Z" }, { "start": "2024-12-17T00:00Z", "end": null }, { "value": "text that is not parsable" }, ], "labels": [ [39.61333, -119.76833], ], "elements": [ ... ], }
where “ident”, “ground_name”, “freq”, and “airspace_type” is only used on extended openair file format by using “AI”, “AG”, “AF”, and “AY”.
Terrain records have the following structure:
{ "type": "terrain", "open": False, "name": "Lake Michigan", "fill": [200, 200, 255], "outline": [0, 1, 0, 0, 255], "zoom": 30.0, "elements": [ ... ], }
Possible elements in both record types, where “lineno” contains the line number of the OpenAir file, in which the element is defined:
# DP elements { "type": "point", "location": [39.61333, -119.76833], "lineno": 100, } # DA elements { "type": "arc", "center": [39.61333, -119.76833], "clockwise": True, "radius": 30.0, "start": 70.0, "end": 180.0, "lineno": 105, } # DB elements { "type": "arc", "center": [39.61333, -119.76833], "clockwise": False, "start": [39.61333, -119.76833], "end": [39.61333, -119.76833], "lineno": 110, } # DC elements { "type": "circle", "center": [39.61333, -119.76833], "radius": 15.0, "lineno": 115, } # DY elements { "type": "airway", "location": [39.61333, -119.76833], "lineno": 120, }
- class aerofiles.openair.LowLevelReader(fp)¶
A low-level reader for the OpenAir airspace file format:
with open('airspace.txt') as fp: reader = LowLevelReader(fp)
see OpenAir file format specification <https://github.com/naviter/seeyou_file_formats/blob/main/OpenAir_File_Format_Support.md>.
Instances of this class read OpenAir files line by line and extract the information in each line as a dictionary. A line like
AN Sacramentofor example is converted to{"type": "AN", "value": "Sacramento"}.The reader should be used as a generator and will return a
(result, error)tuple for each line that is not empty or a comment:for result, error in reader: if error: raise error # or handle it otherwise # handle result
Most lines are just parsed into
typeandvaluestrings. In addition they havelinenowhich contains the line number of the parsed OpenAir file. The following examples should show the lines that are parsed differently:# AT 39:36.8 N 119:46.1W {"type": "AT", "value": [39.61333, -119.76833]} # DA 10,320,200 {"type": "DA", "radius": 10, "start": 320, "end": 200} # DC 1.5 {"type": "DC", "value": 1.5} # DP 39:35:00 N 118:59:20 W {"type": "DP", "value": [39.58333, -118.98888]} # SB 200,200,255 {"type": "SB", "value": [200, 200, 255]} # SP 0,1,0,0,255 {"type": "SP", "value": [0, 1, 0, 0, 255]} # V D=- {"type": "V", "name": "D", "value": False} # V X=39:29.7 N 119:46.5 W {"type": "V", "name": "X", "value": [39.495, -119.775]} # V Z=100 {"type": "V", "name": "Z", "value": 100}
- class aerofiles.openair.Writer(fp=None, encoding='utf-8')¶
A higher-level writer for the OpenAir airspace file format:
with open('airspace.txt', 'wb') as fp: writer = Writer(fp)
- Parameters:
fp – file pointer to write to
encoding – the encoding used for the output
see OpenAir file format specification
This class should be used to write records as described under Reader into a file.
writer.write_record(record)
Currently only airspace records are implemented. Terrain is missing.