Friday, 13 November 2020

A bit of Python

No not a snake... I have been frustrated for a while that if I do a longer walk than about 5 or 6 miles, the Ramblers Planner cannot upload the GPX file I can export from my MapMyWalk walk logs. It just fails saying "Upload error". But I had a suspicion it was because the planner couldn't cope with files that were bigger than a certain size. Poor software engineering to my mind. But never mind. I thought I could see a way around it. If I took the GPX file and removed, say, 9 out of 10 of the trackpoints, I could generate a smaller file and that might upload. But how to do it? I thought a bit of Python might do the job, not that I've much experience of using it.

So, after installing it and a few trials and tribulations around configuration (I abandoned trying to use Eclipse because it was too complicated and overkill for what I was trying to do, and stuck to Notepad++) and syntax (and most of my morning) I came up with this simple Python module*...

And then, taking the output from yesterday's 13.3 mile walk and calling it 'gpxin.gpx', I was able to strip it down to a tenth of the size by...

...and upload the resulting file to generate this...

Yey! I can still hack code. And I can now plot all my MapMyWalk walks on an OS map background!

*The "print" lines are not necessary but give a copy of the output to the console so you can see what is being written to the output file. I also don't need to separately handle the first few lines of the file, so the code could be simpler, but it works.

No comments:

Post a Comment