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

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",
    "floor": "500ft",
    "ceiling": "UNLIM",
    "labels": [
        [39.61333, -119.76833],
    ],
    "elements": [
        ...
    ],
}

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

Instances of this class read OpenAir files line by line and extract the information in each line as a dictionary. A line like AN Sacramento for 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 type and value strings. In addition they have lineno which 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}