Exemple #1
0
def parse_seeyou_waypoints(lines, bounds=None):
    waypoint_list = WaypointList()

    first = True
    for line in lines:
        if first:
            first = False
            continue

        line = line.strip()
        if line == '' or line.startswith('*'):
            continue

        if line == '-----Related Tasks-----':
            break

        fields = []
        line = __CSVLine(line)
        while line.has_next():
            fields.append(line.next())

        if len(fields) < 6:
            continue

        lat = __parse_coordinate(fields[3])
        if bounds and (lat > bounds.top or lat < bounds.bottom):
            continue

        lon = __parse_coordinate(fields[4])
        if bounds and (lon > bounds.right or lon < bounds.left):
            continue

        wp = Waypoint()
        wp.lat = lat
        wp.lon = lon
        wp.altitude = __parse_altitude(fields[5])
        wp.name = fields[0].strip()
        wp.country_code = fields[2].strip()

        if len(fields) > 6 and len(fields[6]) > 0:
            wp.cup_type = int(fields[6])

        if len(fields) > 7 and len(fields[7]) > 0:
            wp.runway_dir = int(fields[7])

        if len(fields) > 8 and len(fields[8]) > 0:
            wp.runway_len = __parse_length(fields[8])

        if len(fields) > 9 and len(fields[9]) > 0:
            wp.freq = float(fields[9])

        if len(fields) > 10 and len(fields[10]) > 0:
            wp.comment = fields[10].strip()

        waypoint_list.append(wp)

    return waypoint_list
Exemple #2
0
def parse_seeyou_waypoints(lines, bounds = None):
    waypoint_list = WaypointList()
    
    first = True
    for line in lines:
        if first: 
            first = False
            continue
        
        line = line.strip()
        if line == '' or line.startswith('*'):
            continue
        
        if line == '-----Related Tasks-----':
            break

        fields = []
        line = __CSVLine(line)
        while line.has_next():
            fields.append(line.next())

        if len(fields) < 6:
            continue

        lat = __parse_coordinate(fields[3]);
        if bounds and (lat > bounds.top or lat < bounds.bottom):
            continue

        lon = __parse_coordinate(fields[4]);
        if bounds and (lon > bounds.right or lon < bounds.left):
            continue

        wp = Waypoint()
        wp.lat = lat;
        wp.lon = lon;
        wp.altitude = __parse_altitude(fields[5]);
        wp.name = fields[0].strip();
        wp.country_code = fields[2].strip();

        if len(fields) > 6 and len(fields[6]) > 0:
          wp.cup_type = int(fields[6])

        if len(fields) > 7 and len(fields[7]) > 0:
            wp.runway_dir = int(fields[7]);

        if len(fields) > 8 and len(fields[8]) > 0:
          wp.runway_len = __parse_length(fields[8]);

        if len(fields) > 9 and len(fields[9]) > 0:
          wp.freq = float(fields[9]);

        if len(fields) > 10 and len(fields[10]) > 0:
          wp.comment = fields[10].strip();

        waypoint_list.append(wp)
        
    return waypoint_list
Exemple #3
0
def __parse_line(line, bounds = None):
    # Ignore comments
    if line.startswith('$'): return None
    
    # Parse latitude
    lat = line[45:52]
    lat_neg = lat.startswith('S')  
    lat = float(lat[1:3]) + float(lat[3:5]) / 60. + float(lat[5:7]) / 3600.
    if lat_neg: lat = -lat
    
    if bounds and (lat > bounds.top or lat < bounds.bottom): return None

    # Parse longitude
    lon = line[52:60]
    lon_neg = lon.startswith('W')  
    lon = float(lon[1:4]) + float(lon[4:6]) / 60. + float(lon[6:8]) / 3600.
    if lon_neg: lon = -lon
    
    if bounds and (lon > bounds.right or lon < bounds.left): return None
    
    # Create waypoint instance
    wp = Waypoint()
    wp.lat = lat
    wp.lon = lon

    # Parse elevation
    elev = line[41:45].strip()
    if elev != '': wp.altitude = float(elev)
    else: wp.altitude = 0.0

    # Extract short name
    wp.short_name = line[:6].strip()
    
    # Parse and strip optional type identifier from short name
    if wp.short_name.endswith('1'):
      wp.type = 'airport'
      wp.short_name = wp.short_name[:5]

    elif wp.short_name.endswith('2'):
      wp.type = 'outlanding'
      wp.short_name = wp.short_name[:5]

    # Extract waypoint name
    wp.name = line[7:41].strip()
    
    # Check for extra data indicator
    if '*' in wp.name or '#' in wp.name:
        # Split data from waypoint name
        data = wp.name[17:]
        wp.name = wp.name[:16].strip()

        # Check waypoint name for glider site indicator
        if wp.name.endswith('GLD'):
            wp.name = wp.name[:-3].strip()
            wp.type = 'glider_site'

        # Extract ICAO code if possible
        icao = data[:4].strip('!? ')
        
        # Check icao code field for glider site indicator
        if icao == 'GLD':
            wp.type = 'glider_site'

        # Check icao code field for ultra light indicator
        if icao == 'ULM' and not wp.type:
            wp.type = 'ulm'

        # Save ICAO code
        if len(icao) == 4:
            wp.icao = icao
        
        # Extract and parse surface character
        if data[4:5] == 'A': wp.surface = 'asphalt'
        elif data[4:5] == 'C': wp.surface = 'concrete'
        elif data[4:5] == 'L': wp.surface = 'loam'
        elif data[4:5] == 'S': wp.surface = 'sand'
        elif data[4:5] == 'Y': wp.surface = 'clay'
        elif data[4:5] == 'G': wp.surface = 'gras'
        elif data[4:5] == 'V': wp.surface = 'gravel'
        elif data[4:5] == 'D': wp.surface = 'dirt'

        # Extract and parse runway length and direction
        runway_len = data[5:8].strip()
        if runway_len != '':
            wp.runway_len = int(runway_len) * 10
        
        runway_dir = data[8:10].strip()
        if runway_dir != '':
            wp.runway_dir = int(runway_dir) * 10
        
        # Extract and parse radio frequency
        freq = data[12:17].strip()
        if len(freq) == 5:
            if freq.endswith('2') or freq.endswith('7'): freq += '5'
            else: freq += '0'
            wp.freq = float(freq) / 1000.

    # Strip uninvited characters from waypoint name
    wp.name = wp.name.rstrip('!?1 ')
    
    # Find waypoint type from waypoint name if not available yet
    if not wp.type:
        if re.search('(^|\s)BERG($|\s)', wp.name): wp.type = 'mountain top'
        if re.search('(^|\s)COL($|\s)', wp.name): wp.type = 'mountain pass'
        if re.search('(^|\s)PASS($|\s)', wp.name): wp.type = 'mountain pass'
        if re.search('(^|\s)TOP($|\s)', wp.name): wp.type = 'mountain top'
        if re.search('(\s)A(\d){0,3}($|\s)', wp.name): wp.type = 'highway exit'
        if re.search('(\s)AB(\d){0,3}($|\s)', wp.name): wp.type = 'highway exit'
        if re.search('(\s)BAB(\d){0,3}($|\s)', wp.name): wp.type = 'highway exit'
        if re.search('(\s)(\w){0,3}XA(\d){0,3}($|\s)', wp.name): wp.type = 'highway cross'
        if re.search('(\s)(\w){0,3}YA(\d){0,3}($|\s)', wp.name): wp.type = 'highway junction'
        if re.search('(\s)STR($|\s)', wp.name): wp.type = 'road'
        if re.search('(\s)SX($|\s)', wp.name): wp.type = 'road cross'
        if re.search('(\s)SY($|\s)', wp.name): wp.type = 'road junction'
        if re.search('(\s)EX($|\s)', wp.name): wp.type = 'railway cross'
        if re.search('(\s)EY($|\s)', wp.name): wp.type = 'railway junction'
        if re.search('(\s)TR($|\s)', wp.name): wp.type = 'gas station'
        if re.search('(\s)BF($|\s)', wp.name): wp.type = 'railway station'
        if re.search('(\s)RS($|\s)', wp.name): wp.type = 'railway station'
        if re.search('(\s)BR($|\s)', wp.name): wp.type = 'bridge'
        if re.search('(\s)TV($|\s)', wp.name): wp.type = 'tower'
        if re.search('(\s)KW($|\s)', wp.name): wp.type = 'powerplant'

    # Format waypoint name properly
    wp.name = wp.name.title()

    # Strip duplicate spaces from waypoint name
    while '  ' in wp.name:
        wp.name = wp.name.replace('  ', ' ')

    # Extract country code
    wp.country_code = line[60:62].strip();

    return wp
def __parse_line(line, bounds = None):
    if line.startswith('$'): return None
    
    lat = line[45:52]
    lat_neg = lat.startswith('S')  
    lat = float(lat[1:3]) + float(lat[3:5]) / 60. + float(lat[5:7]) / 3600.
    if lat_neg: lat = -lat
    
    if bounds and (lat > bounds.top or lat < bounds.bottom): return None

    lon = line[52:60]
    lon_neg = lon.startswith('W')  
    lon = float(lon[1:4]) + float(lon[4:6]) / 60. + float(lon[6:8]) / 3600.
    if lon_neg: lon = -lon
    
    if bounds and (lon > bounds.right or lon < bounds.left): return None
    
    wp = Waypoint()
    wp.lat = lat
    wp.lon = lon

    elev = line[41:45].strip()
    if elev != '': wp.altitude = float(elev)
    else: wp.altitude = 0.0

    wp.short_name = line[:6]
    if wp.short_name.endswith('1'): wp.type = 'airport'
    elif wp.short_name.endswith('2'): wp.type = 'outlanding'
    
    wp.short_name = wp.short_name.strip()
    
    wp.name = line[7:41].strip()
    
    if 'GLD' in wp.name: wp.type = 'glider_site'
    if 'ULM' in wp.name: wp.type = 'ulm'
    
    pos = -1
    if '#' in wp.name: pos = wp.name.find('#')
    if '*' in wp.name: pos = wp.name.find('*')
        
    if pos > -1:        
        data = wp.name[pos + 1:]
        wp.name = wp.name[:pos].strip()
        
        icao = data[:4]
        if not icao.startswith('GLD') and not icao.startswith('ULM'): wp.icao = icao
        
        if data[4:5] == 'A': wp.surface = 'asphalt'
        elif data[4:5] == 'C': wp.surface = 'concrete'
        elif data[4:5] == 'L': wp.surface = 'loam'
        elif data[4:5] == 'S': wp.surface = 'sand'
        elif data[4:5] == 'Y': wp.surface = 'clay'
        elif data[4:5] == 'G': wp.surface = 'gras'
        elif data[4:5] == 'V': wp.surface = 'gravel'
        elif data[4:5] == 'D': wp.surface = 'dirt'

        runway_len = data[5:8].strip()
        if runway_len != '':
            wp.runway_len = int(runway_len) * 10
        
        runway_dir = data[8:10].strip()
        if runway_dir != '':
            wp.runway_dir = int(runway_dir) * 10
        
        freq = data[12:17].strip()
        if len(freq) == 5:
            if freq.endswith('2') or freq.endswith('7'): freq += '5'
            else: freq += '0'
            wp.freq = float(freq) / 1000.
    
    if wp.name.endswith('GLD'):
        wp.name = wp.name[:-3].strip()
    else:
        wp.name = wp.name.rstrip('!?1 ')
    
    if re.search('(^|\s)BERG($|\s)', wp.name): wp.type = 'mountain top'
    if re.search('(^|\s)COL($|\s)', wp.name): wp.type = 'mountain pass'
    if re.search('(^|\s)PASS($|\s)', wp.name): wp.type = 'mountain pass'
    if re.search('(^|\s)TOP($|\s)', wp.name): wp.type = 'mountain top'
    if re.search('(\s)A(\d){0,3}($|\s)', wp.name): wp.type = 'highway exit'
    if re.search('(\s)AB(\d){0,3}($|\s)', wp.name): wp.type = 'highway exit'
    if re.search('(\s)BAB(\d){0,3}($|\s)', wp.name): wp.type = 'highway exit'
    if re.search('(\s)(\w){0,3}XA(\d){0,3}($|\s)', wp.name): wp.type = 'highway cross'
    if re.search('(\s)(\w){0,3}YA(\d){0,3}($|\s)', wp.name): wp.type = 'highway junction'
    if re.search('(\s)STR($|\s)', wp.name): wp.type = 'road'
    if re.search('(\s)SX($|\s)', wp.name): wp.type = 'road cross'
    if re.search('(\s)SY($|\s)', wp.name): wp.type = 'road junction'
    if re.search('(\s)EX($|\s)', wp.name): wp.type = 'railway cross'
    if re.search('(\s)EY($|\s)', wp.name): wp.type = 'railway junction'
    if re.search('(\s)TR($|\s)', wp.name): wp.type = 'gas station'
    if re.search('(\s)BF($|\s)', wp.name): wp.type = 'railway station'
    if re.search('(\s)RS($|\s)', wp.name): wp.type = 'railway station'
    if re.search('(\s)BR($|\s)', wp.name): wp.type = 'bridge'
    if re.search('(\s)TV($|\s)', wp.name): wp.type = 'tower'
    if re.search('(\s)KW($|\s)', wp.name): wp.type = 'powerplant'
        
    wp.name = wp.name.title()
    
    while '  ' in wp.name:
        wp.name = wp.name.replace('  ', ' ')
        
    wp.country_code = line[60:62].strip();
    
    return wp
Exemple #5
0
def __parse_line(line, bounds=None):
    # Ignore comments
    if line.startswith('$'): return None

    # Parse latitude
    lat = line[45:52]
    lat_neg = lat.startswith('S')
    lat = float(lat[1:3]) + float(lat[3:5]) / 60. + float(lat[5:7]) / 3600.
    if lat_neg: lat = -lat

    if bounds and (lat > bounds.top or lat < bounds.bottom): return None

    # Parse longitude
    lon = line[52:60]
    lon_neg = lon.startswith('W')
    lon = float(lon[1:4]) + float(lon[4:6]) / 60. + float(lon[6:8]) / 3600.
    if lon_neg: lon = -lon

    if bounds and (lon > bounds.right or lon < bounds.left): return None

    # Create waypoint instance
    wp = Waypoint()
    wp.lat = lat
    wp.lon = lon

    # Parse elevation
    elev = line[41:45].strip()
    if elev != '': wp.altitude = float(elev)
    else: wp.altitude = 0.0

    # Extract short name
    wp.short_name = line[:6].strip()

    # Parse and strip optional type identifier from short name
    if wp.short_name.endswith('1'):
        wp.type = 'airport'
        wp.short_name = wp.short_name[:5]

    elif wp.short_name.endswith('2'):
        wp.type = 'outlanding'
        wp.short_name = wp.short_name[:5]

    # Extract waypoint name
    wp.name = line[7:41].strip()

    # Check for extra data indicator
    if '*' in wp.name or '#' in wp.name:
        # Split data from waypoint name
        data = wp.name[17:]
        wp.name = wp.name[:16].strip()

        # Check waypoint name for glider site indicator
        if wp.name.endswith('GLD'):
            wp.name = wp.name[:-3].strip()
            wp.type = 'glider_site'

        # Extract ICAO code if possible
        icao = data[:4].strip('!? ')

        # Check icao code field for glider site indicator
        if icao == 'GLD':
            wp.type = 'glider_site'

        # Check icao code field for ultra light indicator
        if icao == 'ULM' and not wp.type:
            wp.type = 'ulm'

        # Save ICAO code
        if len(icao) == 4:
            wp.icao = icao

        # Extract and parse surface character
        if data[4:5] == 'A': wp.surface = 'asphalt'
        elif data[4:5] == 'C': wp.surface = 'concrete'
        elif data[4:5] == 'L': wp.surface = 'loam'
        elif data[4:5] == 'S': wp.surface = 'sand'
        elif data[4:5] == 'Y': wp.surface = 'clay'
        elif data[4:5] == 'G': wp.surface = 'gras'
        elif data[4:5] == 'V': wp.surface = 'gravel'
        elif data[4:5] == 'D': wp.surface = 'dirt'

        # Extract and parse runway length and direction
        runway_len = data[5:8].strip()
        if runway_len != '':
            wp.runway_len = int(runway_len) * 10

        runway_dir = data[8:10].strip()
        if runway_dir != '':
            wp.runway_dir = int(runway_dir) * 10

        # Extract and parse radio frequency
        freq = data[12:17].strip()
        if len(freq) == 5:
            if freq.endswith('2') or freq.endswith('7'): freq += '5'
            else: freq += '0'
            wp.freq = float(freq) / 1000.

    # Strip uninvited characters from waypoint name
    wp.name = wp.name.rstrip('!?1 ')

    # Find waypoint type from waypoint name if not available yet
    if not wp.type:
        if re.search('(^|\s)BERG($|\s)', wp.name): wp.type = 'mountain top'
        if re.search('(^|\s)COL($|\s)', wp.name): wp.type = 'mountain pass'
        if re.search('(^|\s)PASS($|\s)', wp.name): wp.type = 'mountain pass'
        if re.search('(^|\s)TOP($|\s)', wp.name): wp.type = 'mountain top'
        if re.search('(\s)A(\d){0,3}($|\s)', wp.name): wp.type = 'highway exit'
        if re.search('(\s)AB(\d){0,3}($|\s)', wp.name):
            wp.type = 'highway exit'
        if re.search('(\s)BAB(\d){0,3}($|\s)', wp.name):
            wp.type = 'highway exit'
        if re.search('(\s)(\w){0,3}XA(\d){0,3}($|\s)', wp.name):
            wp.type = 'highway cross'
        if re.search('(\s)(\w){0,3}YA(\d){0,3}($|\s)', wp.name):
            wp.type = 'highway junction'
        if re.search('(\s)STR($|\s)', wp.name): wp.type = 'road'
        if re.search('(\s)SX($|\s)', wp.name): wp.type = 'road cross'
        if re.search('(\s)SY($|\s)', wp.name): wp.type = 'road junction'
        if re.search('(\s)EX($|\s)', wp.name): wp.type = 'railway cross'
        if re.search('(\s)EY($|\s)', wp.name): wp.type = 'railway junction'
        if re.search('(\s)TR($|\s)', wp.name): wp.type = 'gas station'
        if re.search('(\s)BF($|\s)', wp.name): wp.type = 'railway station'
        if re.search('(\s)RS($|\s)', wp.name): wp.type = 'railway station'
        if re.search('(\s)BR($|\s)', wp.name): wp.type = 'bridge'
        if re.search('(\s)TV($|\s)', wp.name): wp.type = 'tower'
        if re.search('(\s)KW($|\s)', wp.name): wp.type = 'powerplant'

    # Format waypoint name properly
    wp.name = wp.name.title()

    # Strip duplicate spaces from waypoint name
    while '  ' in wp.name:
        wp.name = wp.name.replace('  ', ' ')

    # Extract country code
    wp.country_code = line[60:62].strip()

    return wp