def unpack(row): ''' Unpacks a list of strings into a GPS tuple @return: a GPS tuple (ts, ((lat, lon), (x, y), alt, spd)). ''' ts = io.as_seconds(row[1].strip(), row[2].strip(), '%d-%m-%Y', '%H:%M:%S') lat = float(row[6].strip()) lon = float(row[7].strip()) x = int(row[10].strip()) y = int(row[11].strip()) a = int(row[8].strip()) s = int(row[9].strip()) return (ts, (lat, lon), (x, y), a, s)
def parse_data_line(line): # Get line parts (pid, lParts) = __split_line(line) try: # Parse latitude latStr = '{:08d}'.format(int(lParts[0])) i = 2 if int(latStr) > 0 else 3 latD = int(latStr[:i]) latDM = float(latStr[i:]) / 10000.0 latDMS = coord.addSeconds(latD, latDM) log.debug('[GSDLoader] Latitude: %s->%s->%s->%s', lParts[0], latStr, (latD, latDM), latDMS) (latD, latM, latS) = latDMS # Parse longitude lonStr = '{:08d}'.format(int(lParts[1])) i = 3 if int(lonStr) > 0 else 4 lonD = int(lonStr[:i]) lonDM = float(lonStr[i:]) / 10000.0 lonDMS = coord.addSeconds(lonD, lonDM) log.debug('[GSDLoader] Longitude: %s->%s->%s->%s', lParts[1], lonStr, (lonD, lonDM), lonDMS) (lonD, lonM, lonS) = lonDMS # Calculate coordinates dms = coord.DMSCoordinate(latD, latM, latS, lonD, lonM, lonS) log.debug('[GSDLoader] DMS: %s', dms) wgs = coord.DMStoWGS(dms) log.debug('[GSDLoader] WGS: %s', wgs) # Latitude & Longitude lat = wgs.getLatitudeDegrees() lon = wgs.getLongitudeDegrees() # Cartesian X & Y if convert_coords: utm = coord.WGStoUTM(wgs) x = utm.x y = utm.y else: x = y = 0 # Date & Time t = '{:6d}'.format(int(lParts[2])) d = '{:6d}'.format(int(lParts[3])) ts = int(io.as_seconds(d, t)) # Speed & Altitude spd = int(lParts[4]) / 100.0 alt = int(lParts[5]) / 10000 except ValueError: log.error('Could not parse point {0}', pid) # Build up data item return (ts, (lat, lon), (x, y), alt, spd)