Author Topic: Splitting a GPX  (Read 6159 times)

quixoticgeek

  • Mostly Harmless
Splitting a GPX
« on: 19 February, 2018, 08:24:46 pm »

I have a GPX route with 15000+ points, and I'd like to split it down to several files each with about 3000 points.

I've tried some of the tools for a google search on "gpx track splitter" and the tools either don't work, or don't do what I need.

Can anyone think of a tool (web based, or Unix based), that will split a gpx into smaller files of a set size?

J
--
Beer, bikes, and backpacking
http://b.42q.eu/

Re: Splitting a GPX
« Reply #1 on: 19 February, 2018, 08:34:15 pm »

Re: Splitting a GPX
« Reply #2 on: 19 February, 2018, 08:41:58 pm »
To satisfy your inner geek, I recommend GPX editor https://sourceforge.net/projects/gpxeditor/

A worthwhile tool to have in your armoury in any event

Re: Splitting a GPX
« Reply #3 on: 19 February, 2018, 08:46:39 pm »

Pingu

  • Put away those fiery biscuits!
  • Mrs Pingu's domestique
    • the Igloo
Re: Splitting a GPX
« Reply #4 on: 19 February, 2018, 08:47:40 pm »
Text editor  :P

T42

  • Apprentice geezer
Re: Splitting a GPX
« Reply #5 on: 20 February, 2018, 08:37:25 am »
To satisfy your inner geek, I recommend GPX editor https://sourceforge.net/projects/gpxeditor/

A worthwhile tool to have in your armoury in any event

Dunno if it matters, but it appears to be incompatible with the current Google Maps API.
I've dusted off all those old bottles and set them up straight

frankly frankie

  • I kid you not
    • Fuchsiaphile
Re: Splitting a GPX
« Reply #6 on: 20 February, 2018, 11:21:01 am »
The current Gmaps API hasn't changed since about 2010.

I'd go with text editor personally.  Just so easy.
I don't think Simple-GPX (which is excellent at what it does) is really what the OP was asking for.
when you're dead you're done, so let the good times roll

T42

  • Apprentice geezer
Re: Splitting a GPX
« Reply #7 on: 20 February, 2018, 01:17:12 pm »
The current Gmaps API hasn't changed since about 2010.

They're had time to fix it since, then.  The old & new APIs were still running concurrently in 2012, though, when I did my last site.

As to splitting GPXes, I've done it in Basecamp, in a rather base, campy fashion: copy A.gpx to B.gpx & C.gpx, then delete the bits of B & C that you don't want.
I've dusted off all those old bottles and set them up straight

Re: Splitting a GPX
« Reply #8 on: 20 February, 2018, 08:14:12 pm »
This might be worth looking at

GPX Track Editor

I use it for cleaning up GPX tracks quite a bit.

Selecting File - Open Track (when in fact all you've got is a route) will cause the program to ask what you want the first timestamp to be and what speed you'd like to have programmed in to the track.

(This will mean that you'll now be working with a'Track' with timestamps - not sure whether this will be an issue for you)

Make sure View - Panes - Points and tracks are both selected and on the RHS of the page will be the 'Points Pane' where you can see an easy to read numbered table of every point on the track.

The test file I used had approx 1800 pts and all I did was scroll down to point 600 and 1200 in turn, right click, select restructuring and add break. You can do this as many times as you like.

In the left hand 'Track  Pane' expand the track by clicking on the '+' symbol and you will see that the original track is now made up of several parts. You can right click on these individual parts and save them independently.

Once you're familiar with the program it would take less than a minute to do.




Feanor

  • It's mostly downhill from here.
Re: Splitting a GPX
« Reply #9 on: 20 February, 2018, 09:35:36 pm »
Can anyone think of a tool (... Unix based), that will split a gpx into smaller files of a set size?

vi

<esc> :wq!

Genosse Brymbo

  • Ostalgist
Re: Splitting a GPX
« Reply #10 on: 20 February, 2018, 09:46:49 pm »
Can anyone think of a tool (... Unix based), that will split a gpx into smaller files of a set size?

vi

<esc> wq!
:thumbsup:  Best done on a SIMH PDP-11 emulator and BSD on your smartphone.  No need for 32-bit addressing and infeasibly large amounts of memory.
The present is a foreign country: they do things differently here.

Re: Splitting a GPX
« Reply #11 on: 20 February, 2018, 10:54:35 pm »
<esc> wq!

ZZ

it's quicker and two keystrokes fewer: https://vi.stackexchange.com/questions/5723/what-are-the-differences-between-wqcr-xcr-and-zz-when-exiting-vim

(ok, they're not quite equivalent, but close enough for most situations...)

"Yes please" said Squirrel "biscuits are our favourite things."

Re: Splitting a GPX
« Reply #12 on: 22 February, 2018, 01:14:24 am »
I don't think Simple-GPX (which is excellent at what it does) is really what the OP was asking for.

It's pretty close though, surely - it won't let you split a 15,000+ point GPX into 3,000 point chunks, but it will let you split a (say) 1630km GPX into 300km chunks.

frankly frankie

  • I kid you not
    • Fuchsiaphile
Re: Splitting a GPX
« Reply #13 on: 22 February, 2018, 09:15:17 am »
It doesn't look as though it can split a track without also simplifying it.  Even the lowest filter setting (1 metre) will wipe out quite a lot of points.
when you're dead you're done, so let the good times roll

Re: Splitting a GPX
« Reply #14 on: 22 February, 2018, 10:23:15 pm »
But if it's currently 15k points for a 1600km route - I'm assuming this is probably the GPX for the Race Around the Netherlands - then it's already relatively sparse on points, so Phil's reduction algorithms probably won't take too many out.

(In any case, I thought you were the arch-advocate for simplified GPXs that used as little bandwidth as possible!)

quixoticgeek

  • Mostly Harmless
Re: Splitting a GPX
« Reply #15 on: 22 February, 2018, 10:29:36 pm »
But if it's currently 15k points for a 1600km route - I'm assuming this is probably the GPX for the Race Around the Netherlands - then it's already relatively sparse on points, so Phil's reduction algorithms probably won't take too many out.

(In any case, I thought you were the arch-advocate for simplified GPXs that used as little bandwidth as possible!)

Assumption correct (am I that transparent?).

It's not that sparse on points, but I wouldn't want to go much sparser, or there's the risk of ambiguity in the built up areas it passes through. I tried loading it into gpsies so I could make 300km overlapping chunks out of it, but gpsies drops it down to 3000 points, and looses way too much detail.

I am seriously considering something with sed, awk and vi...

J
--
Beer, bikes, and backpacking
http://b.42q.eu/

fuaran

  • rothair gasta
Re: Splitting a GPX
« Reply #16 on: 22 February, 2018, 10:47:13 pm »
You could try QMapShack. https://bitbucket.org/maproom/qmapshack/wiki/Home

Maybe more useful to split the track into sections between controls, instead of simply splitting by number of points.

Re: Splitting a GPX
« Reply #17 on: 22 February, 2018, 11:14:07 pm »
But if it's currently 15k points for a 1600km route - I'm assuming this is probably the GPX for the Race Around the Netherlands - then it's already relatively sparse on points, so Phil's reduction algorithms probably won't take too many out.

(In any case, I thought you were the arch-advocate for simplified GPXs that used as little bandwidth as possible!)

Assumption correct (am I that transparent?).

It's not that sparse on points, but I wouldn't want to go much sparser, or there's the risk of ambiguity in the built up areas it passes through. I tried loading it into gpsies so I could make 300km overlapping chunks out of it, but gpsies drops it down to 3000 points, and looses way too much detail.

I am seriously considering something with sed, awk and vi...

J

I've just split the gpx file that I downloaded off the RATN website using GPX Track editor in to 3 stages of approx 10,000, 10,000 and 11,000pts - with no loss of points  (Total pts 31,163) - it's very easy ! Or do the added timestamps present a problem for you?

GPS Track Editor

Re: Splitting a GPX
« Reply #18 on: 23 February, 2018, 09:38:42 pm »
I am seriously considering something with sed, awk and vi...
if it's a one-off split into 5 files, use vi.

this is based on a track gpx from cycle.travel, that has 1 line per <trkpt>, 8 lines above the first <trkpt>, and 3 lines after the last <trkpt>

:1              go to first line
"a8yy         copy 8 lines into buffer a (or however many lines it is above the first <trkpt>)
G               go to the end
2k             go up 2 lines, to <trkseg>, after the last <trkpt>
"b3yy         copy the last 3 lines into buffer b
:1             go back to the top

change the name of the track to add " section 1" 
moving to the name item will be click on it, using the arrow keys, or using the hjkl keys (h=left, j=down, k=up, l=left), depending on the version of vi you are using.
When the cursor is in the right place, go into edit mode by either "i" (insert before), "a" (append after) or "R" (replace/overtype), type the addition to the name, then use the <esc> key to get back to command mode.

:8             go to line 8 (line above the first <trkpt>)
3000j        go down 3000 <trkpt>s (if a <trkpt> </trkpt> pair occupy several lines, multiply 3000 by the value of several)
"bp           paste buffer b below the 3000th <trkpt>
2j             go down 2 lines to the </gpx> line
:1,.w section1.gpx        write out the first segment to file section1.gpx
:1,.d         delete the first segment
"aP           paste buffer a above the <trkpt> the delete left you on

then change the name of the track in the pasted header section, and repeat from ":8", until "3000j" fails because there aren't that many points left, at which point write out what's left by ...

:1,$ w sectionN.gpx
:q!           quit without saving, so you've still got the 15000 line version

I mostly use WinVi, as being a simple executable that doesn't need an install


quixoticgeek

  • Mostly Harmless
Re: Splitting a GPX
« Reply #19 on: 04 March, 2018, 08:06:57 pm »
I've just split the gpx file that I downloaded off the RATN website using GPX Track editor in to 3 stages of approx 10,000, 10,000 and 11,000pts - with no loss of points  (Total pts 31,163) - it's very easy ! Or do the added timestamps present a problem for you?

GPS Track Editor

Alas that seems to be windows only, so not an option. I need something that runs on Linux.

J
--
Beer, bikes, and backpacking
http://b.42q.eu/

Re: Splitting a GPX
« Reply #20 on: 05 March, 2018, 12:17:26 pm »
http://www.gpxeditor.co.uk/

... may do what you need.

Re: Splitting a GPX
« Reply #21 on: 05 March, 2018, 01:06:35 pm »
http://www.gpxeditor.co.uk/

... may do what you need.

This (at least the subscribed to version) will let you split the track down into smaller ones, but it's a case of pointing at the place where you want the split to be made rather than being able to specify a certain number of track points.

The info box for each track will show you how many points it consists of, so if you're not adverse to a bit of trial and error you could undo and redo until you get to something like the size you're after.

Re: Splitting a GPX
« Reply #22 on: 05 March, 2018, 08:47:36 pm »
If you just want it done then zip it up and email it to me (alex @ <my_acf_username> .org ) and I'll split it for you. Just let me know how you want it split up.

If you want a way of doing them again and again in the future then that's a different matter. If I get a chance tomorrow I'll see if I can knock up a quick script to do it that you could then run on Linux.
"Yes please" said Squirrel "biscuits are our favourite things."

frankly frankie

  • I kid you not
    • Fuchsiaphile
Re: Splitting a GPX
« Reply #23 on: 06 March, 2018, 09:49:17 am »
An advantage of using a text editor for this is that you can easily create overlaps at the splits.  An advantage of using a point-and-click map-based tool is that you can easily put the splits precisely at control points.
when you're dead you're done, so let the good times roll

Phil W

Re: Splitting a GPX
« Reply #24 on: 08 April, 2018, 05:46:55 pm »
But if it's currently 15k points for a 1600km route - I'm assuming this is probably the GPX for the Race Around the Netherlands - then it's already relatively sparse on points, so Phil's reduction algorithms probably won't take too many out.

(In any case, I thought you were the arch-advocate for simplified GPXs that used as little bandwidth as possible!)

Assumption correct (am I that transparent?).

It's not that sparse on points, but I wouldn't want to go much sparser, or there's the risk of ambiguity in the built up areas it passes through. I tried loading it into gpsies so I could make 300km overlapping chunks out of it, but gpsies drops it down to 3000 points, and looses way too much detail.

I am seriously considering something with sed, awk and vi...

J

Been away from the forum for a few months so did not see this discussion till now.


Can I just tackle this sparseness concern.  Simple-gpx does not just remove points indiscriminately, it selectively removes points, whilst retaining the shape of the track.

For instance if a road goes dead straight for 400 metres. You only require two track points, one at the start and one at the end. If it has a kink in the road, then you need three track points to match the road.  If you have a complicated route through a city centre then you need a lot more track points.

So if you set the tolerance to 1M, the new track if overlaid on top of the old track will not differ in alignment by more than one metre. If you were sat on your bike, with your feet down,  and the tracks were painted on the road they would both pass within your two feet assuming you were on the route. Also bear in mind that 1m difference on a gps display is going to be near enough invisible at most zoom levels, and the line of the tracks may well occupy the same pixels on your display.

I used it for the 2100km Wild Atlantic Way Audax in 2016.  A single track, and at no point did I have a problem.

You concerns about losing precision in complex city environments are unfounded.  If you still don't believe me run your track through my tool then load the resulting track onto some mapping then zoom right in to just such a city you are concerned about, and see for yourself. It can of course also split the track for you, but that is by distance, with the longest split being 300km.

I use my own tool simple-gpx for all my audaxes and have yet to have an issue with navigation on any of them. That is with leaving it on the default of 10m tolerance. Bear in mind your gps is only accurate to about 3-5m, best case, so 1m tolerance is already more accurate than that.

In summary, I think your fears are unfounded, though I understand when you have not used the tools before. Perhaps try the tool on a 200 you have planned, to see what you think. Load the original track as backup as well, to give you confidence the first time.

The tool uses the library linked below as the base for the track simplification. I had to adapt it to talk latitude and longitude and deal with closed loops (typical audax). But have a play to see how many points can be removed before you notice a difference. It might surprise you.

https://mourner.github.io/simplify-js/