Author Topic: GPX/GPS utilities/scripts  (Read 2983 times)

GPX/GPS utilities/scripts
« on: 20 May, 2009, 11:08:35 am »
Been playing around with some of my scripts for messing with GPX files, getting them ready for events and for looking at them afterwards.

My usual method (for long rides such as Audaxes) is this:

1) Plot route on bikely with follow-roads mode off, and using one point per routesheet instruction, naming each point with a shortened version of the instruction (L/R/SO/LR/E3/etc)
2) Download this sparse GPX file (bikely gives you a bunch of named waypoints plus a track with elevations of these points). I junk the track section and convert the waypoints to a route by changing "wpt" to "rtept" and adding in a <rte><name>name</name> ... </rte> bits.
3) Manually check that I've not mislabeled any of the L/R instructions
4) Plot the route on bikehike using follow roads and download the GPX (track with elevations). Find the summits of the major climbs (annoyingly tricky to find the actual locations and heights) and add these as summit points on the route for the GPX.
5) Split the route GPX file at the appropriate places (to keep within limits).
6) Add in any other appropriate routes (between stations, hotels, start/finish, etc) from a library of previously made routes, or from a new one.
7) Check that the points with the route GPX are uniquely named, and not more than 6 characters.
8) Upload to GPS.

Certain bits of this are a real faff so I want to automate some of it.

Plotting the route (1) is good as I get to see where I'm going, can tell if the routesheet is off for any reason, and I've usually got a good memory for knowing where I'll be passing towns/shops/pubs or train stations. This will always be manual.

2) Splitting the file and changing the waypoints to routepoints can be automated.
3) I've got a script that checks the angle of the turn at each routepoint (compare bearings of lines from previous routepoint to current, and from current to next routepoint). Not perfect but it does help catch the odd one that creeps through.
4) The summit point finding is annoying and I've just sorted out a script to do this. It works by doing thing following:-

do {
  for each point
     delete it if the previous elevation is lower and the next point's elevation is higher
     or, delete it if the previous elevation is higher and the next point's elevation is lower
  # at this point we have a series of peaks and troughs although many of the troughs
  # are very small climbs/descents which need to be removed
  for each point
     if this is a trough point (i.e. previous and next points are higher)
        if previous elevation is less than 50m higher then remove this current point
        or, if next elevation is less than 50m higher then remove this current point
} while( number of points removed in this iteration > 0 )

The second part slowly filters out all of the small climbs (under 50m), or bits where it descends for a few meters, and the first part then repeats the cleanup of subsequent series of descents/ascents.

The 50m figure is what I'd consider a minimum "climb" that I'd like to know about in advance. The lower the figure you use here and the more climbs it will identify. Running this against the BCM elevation plot it found the peak of every climb I'd identified by looking at the elevation plot, plus the Bow Street climb (which I'd missed). It's also a hell of a lot quicker!

Once I've found the peaks I can make routepoints for them with the summit heights in their name, and then merge them into my route in the right place (by looking for the nearest routepoints, easy for a computer to do, tricky for a human to look at a lat/lon and work out where it goes). I also want to warn if they appear very shortly after a turn (i.e. I'd have no real warning of the end of the climb if I didn't look at the map page) and decide if I need to move it.

This one single job (finding the summit points and adding them to the GPX) took me over an hour for the BCM route. This new script does it in seconds and the manual check is only a minute or so.

The rest of the jobs are more checking (unique names, character limits).

Upload is manual using GPS Trackmaker but I could automate it with gpsbabel, but I know that GPSTM works and I trust it.

Post ride I want to look at how much climbing there was, filtering out the glitches, and see how much time in hand I had/lost as the ride went along. It's a bit more time consuming as the ride is often split over various tracklogs/segments and also includes non-ride sections such as rides to the start from a hotel or station.

All done in Perl at the moment with no proper XML parsing (just regexp) so it only really works on GPX files in a certain format. Proper XML parsers are complex and too feature rich for my needs. I'm planning on cleaning it all up and sticking it up somewhere for downloading. I could, theoretically, make it into one single application that could produce the graphing too, but that's time consuming.

So, are there any other things I could be doing? Anything else that people are constantly doing with GPX files that could be made easier?

<awaits tumbleweed>
"Yes please" said Squirrel "biscuits are our favourite things."

Chris N

Re: GPX/GPS utilities/scripts
« Reply #1 on: 20 May, 2009, 11:53:29 am »
Hmmm, none of that. ;D

I do check the full route in bikehike as well as plotting it in bikely, and use the 1:25,000/1:50,000 maps on bikehike/Streetmap/OS get-a-map to find spot heights.  I then add them back in on bikely.  I only put really big/obvious summits in, and then only if they're not close to a junction/instruction.

I'll also add in guiding points if the route needs it (large bends in the road, odd junctions in towns, etc.

I don't create one route then split it - but I do create multiple routes in bikely if I need to.  Often I'll annotate the route sheet with the routepoint numbers (AA, AB, etc.) to work out how many routes I'll need to break it into.

Then I manually scroll through the route on bikely, checking for missed turns and incorrect labelling.

I then follow your method of converting from bikely gpx to a usable route.

All of this is done manually cos I don't know anything about programming - I'd guess that it took me a couple of hours in total to get the files ready for the BCM.  I don't mind spending the time doing this as I enjoy it and it helps prep for the ride itself - give a good idea of the route and means I don;t need to refer to the routesheet at all on the event.

Panoramix

  • .--. .- -. --- .-. .- -- .. -..-
  • Suus cuique crepitus bene olet
    • Some routes
Re: GPX/GPS utilities/scripts
« Reply #2 on: 20 May, 2009, 08:39:31 pm »
I am currently writing a small python script that does a post mortem of a ride (climbing, time stopped, distance, average speed) + electronic mile eater diary (dump a month of track and it tells you how much you have ridden every day).

 Tomorrow I have to go to a meeting in London, so hope to make some progress in the train.

I can't do Perl, I am just a human being...
Chief cat entertainer.

Re: GPX/GPS utilities/scripts
« Reply #3 on: 20 May, 2009, 10:36:22 pm »
Should be easily translated to python. I tend to write C in Perl rather than using anything majorly Perl-ish.
"Yes please" said Squirrel "biscuits are our favourite things."

Panoramix

  • .--. .- -. --- .-. .- -- .. -..-
  • Suus cuique crepitus bene olet
    • Some routes
Re: GPX/GPS utilities/scripts
« Reply #4 on: 20 May, 2009, 11:47:54 pm »
Should be easily translated to python. I tend to write C in Perl rather than using anything majorly Perl-ish.
I just meant that I am only an amateur and can't do "serious" languages such as Java, C, C++ or perl.
If I manage something useful, I will share!
Chief cat entertainer.

frankly frankie

  • I kid you not
    • Fuchsiaphile
Re: GPX/GPS utilities/scripts
« Reply #5 on: 21 May, 2009, 10:05:02 am »
The second part slowly filters out all of the small climbs (under 50m), or bits where it descends for a few meters, and the first part then repeats the cleanup of subsequent series of descents/ascents.

That sounds as though it could be a really useful tool for AAA-assessing, as an aid to standardising at least one method of measuring climbing.  Steve A.A.A. Snook might be interested.
when you're dead you're done, so let the good times roll

Re: GPX/GPS utilities/scripts
« Reply #6 on: 21 May, 2009, 10:46:55 am »
The second part slowly filters out all of the small climbs (under 50m), or bits where it descends for a few meters, and the first part then repeats the cleanup of subsequent series of descents/ascents.

That sounds as though it could be a really useful tool for AAA-assessing, as an aid to standardising at least one method of measuring climbing.  Steve A.A.A. Snook might be interested.

50m climb minimum is pretty harsh, it reduces the Bryan Chapman to just 2950m climbing. Setting it at 10m gives 5600m climbing.

Here are graphs of the iterations of the cleanup:



And the final output:-



(Note that these are just heights of peaks, the horizontal axis is linear).
"Yes please" said Squirrel "biscuits are our favourite things."

frankly frankie

  • I kid you not
    • Fuchsiaphile
Re: GPX/GPS utilities/scripts
« Reply #7 on: 21 May, 2009, 01:36:46 pm »
50m climb minimum is pretty harsh, it reduces the Bryan Chapman to just 2950m climbing. Setting it at 10m gives 5600m climbing.

Yes obviously, its a matter of establishing a suitable standard, and one that chimes well with the well-worn contour-counting methods.

(Personally, I would definitely want to know about 50m climbs! ;- )
when you're dead you're done, so let the good times roll

Panoramix

  • .--. .- -. --- .-. .- -- .. -..-
  • Suus cuique crepitus bene olet
    • Some routes
Re: GPX/GPS utilities/scripts
« Reply #8 on: 22 May, 2009, 01:16:42 pm »
I have made some progress yesterday, now I can parse a GPX file sticking all the info in an easy to use object so that I can do all the imaginable postprocessing without too much effort.

I need to put a bit more effort in error checking as my tracks never seem to be perfect and I get exceptions because of this; I will delete the corrupted trackpoints. 

I plan to do contour counting also:
  if elevation1 div 10 < elevation2 div 10 then climbing +=10

Chief cat entertainer.