View Single Post
Old 07-13-2009, 11:08 PM   #8 (permalink)
dcb
needs more cowbell
 
dcb's Avatar
 
Join Date: Feb 2008
Location: ÿ
Posts: 5,038

pimp mobile - '81 suzuki gs 250 t
90 day: 96.29 mpg (US)

schnitzel - '01 Volkswagen Golf TDI
90 day: 53.56 mpg (US)
Thanks: 158
Thanked 269 Times in 212 Posts
I would love to see a real data file. I looked at the gpx schema data definiton(s) at http://www.topografix.com/GPX/1/0/gpx.xsd but did not see any elements named "trip", maybe "trip" is a data value?

here it is with ele added, (and updated for python 2.5+) had to make the ele append conditional because one entry didn't have it, which is legal because ele is defined as minOccurs="0" in the xsd (as is "name" BTW).

These are data from waypoints, identified by wpt tags in the xml.

PHP Code:
import xml.etree.cElementTree as ET
import string

if __name__ == '__main__':

    
mainNS=string.Template("{http://www.topografix.com/GPX/1/0}$tag")

    
wptTag=mainNS.substitute(tag="wpt")
    
nameTag=mainNS.substitute(tag="name")
    
eleTag=mainNS.substitute(tag="ele")

    
et=ET.parse(open("everything.gpx"))

    for 
wpt in et.findall("//"+wptTag):
        
wptinfo=[]
        
wptinfo.append(wpt.get("lat"))
        
wptinfo.append(wpt.get("lon"))
        
wptinfo.append(wpt.findtext(nameTag))
        if (
wpt.findtext(eleTag)):
            
wptinfo.append(wpt.findtext(eleTag))

        print 
",".join(wptinfo
getting started (windows), if anyone is interested

installed python 2.6.2 (msi)
Download Python Software

created a working directory

saved the code to gpx.py in the working dir

saved the .gpx data file to the same directory as everything.gpx

ran: gpx.py from the working dir
output:
C:\Python26\wip>gpx.py
42.438878,-71.119277,5066,44.586548
42.439227,-71.119689,5067,57.607200
42.438917,-71.116146,5096,44.826904
42.443904,-71.122044,5142,50.594727
42.447298,-71.121447,5156,127.711200
42.454873,-71.125094,5224,96.926400
42.459079,-71.124988,5229,82.600800
...
__________________
WINDMILLS DO NOT WORK THAT WAY!!!

Last edited by dcb; 07-13-2009 at 11:17 PM..
  Reply With Quote