Following a number of inquiries about how I'm dealing with GPS data in GPX format, here's a snapshot of my minimalist Python GPX parser (which is now officially stalled due to the end of my vacation). Like most of my Python stuff, it has zero dependencies (I went with minidom since it gave me nice, easy to handle element lists):
import sys, string from xml.dom import minidom, Node class GPXParser: def __init__(self, filename): self.tracks = {} try: doc = minidom.parse(filename) doc.normalize() except: return # handle this properly later gpx = doc.documentElement for node in gpx.getElementsByTagName('trk'): self.parseTrack(node) def parseTrack(self, trk): name = trk.getElementsByTagName('name')[0].firstChild.data if not name in self.tracks: self.tracks[name] = {} for trkseg in trk.getElementsByTagName('trkseg'): for trkpt in trkseg.getElementsByTagName('trkpt'): lat = float(trkpt.getAttribute('lat')) lon = float(trkpt.getAttribute('lon')) ele = float(trkpt.getElementsByTagName('ele')[0].firstChild.data) rfc3339 = trkpt.getElementsByTagName('time')[0].firstChild.data self.tracks[name][rfc3339]={'lat':lat,'lon':lon,'ele':ele} def getTrack(self, name): times = self.tracks[name].keys() points = [self.tracks[name][time] for time in times.sort()] return [(point['lat'],point['lon']) for point in points]
This is just the basics - KML generation from here on is trivial, but rather verbose, so I clipped it.
More on this later (depending on free time).