Created
December 28, 2011 08:58
-
-
Save mrgriscom/1527181 to your computer and use it in GitHub Desktop.
parse GPX trackfiles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from xml.etree import ElementTree as et | |
import sys | |
from datetime import datetime | |
def _(tag): | |
return '{%s}%s' % ('http://www.topografix.com/GPX/1/1', tag) | |
def parse(f): | |
node = et.parse(f).getroot() | |
for p in node.findall('.//%s' % _('trkpt')): | |
lat = float(p.attrib['lat']) | |
lon = float(p.attrib['lon']) | |
alt = float(p.find(_('ele')).text) | |
timestamp = datetime.strptime(p.find(_('time')).text, '%Y-%m-%dT%H:%M:%SZ') | |
yield (timestamp, lat, lon, alt) | |
if __name__ == "__main__": | |
with open(sys.argv[1]) as f: | |
print sorted(list(parse(f))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment