Ejemplo n.º 1
0
def import_airfield_data():
    footer_line_count = None
    ad_added = 0
    with open_ad_positions_file() as f:
        for line in f:
            if line.startswith('#'):
                continue
            split = line.split(maxsplit=2)
            if len(split) == 3:
                icao_code, lat_lon, name = split
                coords = EarthCoords.fromString(lat_lon)
                world_navpoint_db.add(Airfield(icao_code, coords,
                                               name.strip()))
                ad_added += 1
            elif len(split) == 0:
                continue
            elif len(split) == 1 and footer_line_count == None:
                footer_line_count = int(split[0])
            else:
                raise ValueError(
                    'Bad or illegal spec line in AD positions file: %s' %
                    line.strip())
    if footer_line_count == None or footer_line_count != ad_added:
        print('ERROR: inconsistencies detected in the AD positions file.')
        print('This is usually caused by an interrupted extraction process. ' \
         'Running the "cleanUp.sh" script should solve the problem in this case.')
        raise ValueError('AD data corrupt')
def get_ground_elevation_map(location_code):
    try:
        with open(elev_map_file_fmt % location_code, encoding='utf8') as f:
            nw = se = None
            line = f.readline()
            while nw == None and line != '':
                tokens = line.split('#', maxsplit=1)[0].split()
                if tokens == []:
                    line = f.readline()
                elif len(tokens) == 2:
                    nw = EarthCoords.fromString(tokens[0])
                    se = EarthCoords.fromString(tokens[1])
                else:
                    raise ValueError('invalid header line')
            if nw == None:
                raise ValueError('missing header line')
            matrix = []
            xprec = None
            line = f.readline()
            while line.strip() != '':
                values = [
                    float(token)
                    for token in line.split('#', maxsplit=1)[0].split()
                ]
                if xprec == None:
                    xprec = len(values)
                elif len(values) != xprec:
                    raise ValueError('expected %d values in row %d' %
                                     (xprec, len(matrix) + 1))
                matrix.append(values)  # add row
                line = f.readline()
        # Finished reading file.
        result = ElevationMap(nw.toRadarCoords(), se.toRadarCoords(),
                              len(matrix), xprec)
        for i, row in enumerate(matrix):
            for j, elev in enumerate(row):
                result.setElevation(i, j, elev)
        return result
    except ValueError as err:
        print('Error in elevation map: %s' % err)
Ejemplo n.º 3
0
def read_point(s):
    match = re_point.fullmatch(s)
    if match:
        if match.group('named') == None:  # lat/lon coordinates in SCT format
            lat, lon = s.split()
            lat_d, lat_m, lat_s = lat[1:].split('.', maxsplit=2)
            lon_d, lon_m, lon_s = lon[1:].split('.', maxsplit=2)
            return EarthCoords.fromString('%sd%sm%ss%s,%sd%sm%ss%s' \
             % (lat_d, lat_m, lat_s, lat[0].upper(), lon_d, lon_m, lon_s, lon[0].upper()))
        else:  # named point
            try:
                return env.navpoints.findUnique(
                    match.group('named')).coordinates
            except NavpointError as err:
                raise ValueError('Named point out of range or not unique: %s' %
                                 s)
    else:
        raise ValueError('Not a valid point spec: %s' % s)
def read_point_spec(specstr, db):
    mvlst = specstr.split('>')
    pbase = mvlst.pop(0)
    try:
        if ',' in pbase and '~' not in pbase:
            result = EarthCoords.fromString(pbase)
        else:
            result = navpointFromSpec(pbase, db).coordinates
    except NavpointError:
        raise ValueError(
            'No navpoint for "%s" or navpoint not unique (consider using `~\' operator)'
            % pbase)
    else:
        while mvlst != []:
            mv = mvlst.pop(0).split(',')
            if len(mv) == 2:
                radial = Heading(float(mv[0]), True)
                distance = float(mv[1])
                result = result.moved(radial, distance)
            else:
                raise ValueError('Bad use of `>\' in point spec "%s"' %
                                 specstr)
        return result