Yet Another Cycling Forum

General Category => The Knowledge => GPS => Topic started by: quixoticgeek on 19 February, 2018, 08:24:46 pm

Title: Splitting a GPX
Post by: quixoticgeek 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
Title: Re: Splitting a GPX
Post by: Sea of vapours on 19 February, 2018, 08:34:15 pm
Try this.
https://simple-gpx.herokuapp.com/
Title: Re: Splitting a GPX
Post by: Ham 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
Title: Re: Splitting a GPX
Post by: jsabine on 19 February, 2018, 08:46:39 pm
Try this.
https://simple-gpx.herokuapp.com/

Created by Phil W OTP: more detail here (https://yacf.co.uk/forum/index.php?topic=97952.msg2039669#msg2039669).

It works.
Title: Re: Splitting a GPX
Post by: Pingu on 19 February, 2018, 08:47:40 pm
Text editor  :P
Title: Re: Splitting a GPX
Post by: T42 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.
Title: Re: Splitting a GPX
Post by: frankly frankie 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.
Title: Re: Splitting a GPX
Post by: T42 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.
Title: Re: Splitting a GPX
Post by: wajcgac on 20 February, 2018, 08:14:12 pm
This might be worth looking at

GPX Track Editor (http://www.gpstrackeditor.com/)

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.



Title: Re: Splitting a GPX
Post by: Feanor 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!
Title: Re: Splitting a GPX
Post by: Genosse Brymbo 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.
Title: Re: Splitting a GPX
Post by: Greenbank 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...)

Title: Re: Splitting a GPX
Post by: jsabine 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.
Title: Re: Splitting a GPX
Post by: frankly frankie 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.
Title: Re: Splitting a GPX
Post by: jsabine 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!)
Title: Re: Splitting a GPX
Post by: quixoticgeek 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
Title: Re: Splitting a GPX
Post by: fuaran 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.
Title: Re: Splitting a GPX
Post by: wajcgac 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 (http://www.gpstrackeditor.com/)
Title: Re: Splitting a GPX
Post by: andrew_s 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 (http://www.winvi.de/en/download.html), as being a simple executable that doesn't need an install

Title: Re: Splitting a GPX
Post by: quixoticgeek 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 (http://www.gpstrackeditor.com/)

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

J
Title: Re: Splitting a GPX
Post by: tonyh on 05 March, 2018, 12:17:26 pm
http://www.gpxeditor.co.uk/

... may do what you need.
Title: Re: Splitting a GPX
Post by: nikki 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.
Title: Re: Splitting a GPX
Post by: Greenbank 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.
Title: Re: Splitting a GPX
Post by: frankly frankie 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.
Title: Re: Splitting a GPX
Post by: Phil W 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/