+Rotareneg Posted January 10, 2011 Posted January 10, 2011 I made this little Python script to process the GPX files output from NGS»GPX 2 and strip out the PIDs that head each and every line in the embedded datasheet, making them much easier to read on a hand-held GPS. First, you need Python 3.x installed. Then copy and paste the script into a text file and rename it with a .py extension. Then you can just drag a .gpx file onto the script to run it. A console window will appear and show the PIDs as it trims them, and then it will overwrite the .gpx file with the trimmed version. Don't run it more than once on the same file or it'll trim actual text from each datasheet line. Also, you probably shouldn't feed it really huge files unless you've got plenty of memory: a 90 meg GPX with all the marks in Kansas peaked at 3 gigs of memory while running. And, of course, the disclaimer: If the program causes problems which end up with you thinking "I have no mouth, and I must scream" or somthing even worse, don't blame me. import io,sys,time from xml.dom.minidom import parse if len(sys.argv) > 1: print('File to read: '+sys.argv[1]) else: print('No file to read.') time.sleep(3) quit() doc = parse(sys.argv[1]) gpx = doc.getElementsByTagName('gpx')[0] wpts = gpx.getElementsByTagName('wpt') for i in wpts: disc = i.getElementsByTagName( 'Groundspeak:cache')[0].getElementsByTagName( 'Groundspeak:long_description')[0].firstChild if disc != None: print(disc.data[0:8]) txt = io.StringIO() out = io.StringIO() txt.write(disc.data) txt.seek(0) pid = txt.readline()[0:6] txt.seek(0) for line in txt: if line == (pid + '\n'): print('\n',end='',file=out) else: print(line[7:len(line)],end='',file=out) disc.data = out.getvalue() o = open(sys.argv[1],'w') o.write(doc.toxml()) o.close() doc.unlink() Quote
+Bullygoat29 Posted January 11, 2011 Posted January 11, 2011 Well I installed python and saved the text to a script file and ran it. Doesn't work for me. And I don't work with python so I have no idea how to help fix it. Quote
+Rotareneg Posted January 12, 2011 Author Posted January 12, 2011 Well I installed python and saved the text to a script file and ran it. Doesn't work for me. And I don't work with python so I have no idea how to help fix it. The forum broke it by capitalizing the 'Groundspeak:cache' string on lines 17 and 18, something that the " " block is [i]supposed[/i] to prevent. To fix the program just make the G in Groundspeak lower case and it'll run. Quote
+Bullygoat29 Posted January 12, 2011 Posted January 12, 2011 Ok that fixed that. Now is there a way to get the command window to stay open? I've got a file that errors out but I can't read what the program is spitting out about it. Thanks again. Quote
+Rotareneg Posted January 12, 2011 Author Posted January 12, 2011 You can run it from a command line, like this for example: F:\GPS\Benchmarks>C:\Python31\python trim_pids.py trego.gpx Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.