This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

Shell tools or scripts to split GPX files based on time

2
1

I am using my GPX files in photo and video processing, and at times need to back track to older archives. I have currently blended all my GPX files into a combined archive, but this is now too big, so that many of the tools I am using are unable to find the data.

I am therefor looking for a tool or shell commands I can use to split the combined archive into monthly files (or if that is still too big, daily files) That way I don't have to look through my entire database in order to find the correct traces.

gpsbabel might be possible, but filtering is still confusing for me.

asked 09 Jan '16, 22:10

Skippern's gravatar image

Skippern
166157
accept rate: 33%


One Answer:

6

gpsbabel can do the low-level filtering for you, but it is a bit awkward, especially if your GPX file has more than one data type (route, track, or waypoint). You would then have to wrap this in a script to process by month or day or whatever.

Here are some examples.

If you have a GPX file of only tracks, and you want only tracks from the year 2014 (2014-01-01 to 2015-01-01), you could use something like this:

gpsbabel -i gpx -f in.gpx \
   -x track,start=20140101,stop=20150101 \
   -o gpx -F out.gpx

Make sure none of your tracks crosses the start or stop date/times, because gpsbabel filters the trackpoints (not the tracks) by trackpoint date/time, and you will end up with partial tracks.

If your GPX file has only waypoints, you have to transform them to use the filter:

gpsbabel -i gpx -f in.gpx \
    -x transform,trk=wpt,del \
    -x track,start=20140101,stop=20150101 \
    -x transform,wpt=trk,del \
    -o gpx -F out.gpx

If your GPX file has both waypoints and tracks, you have to run 2 passes, once per type. Then merge the results (if desired).

gpsbabel -i gpx -f in.gpx \
    -x nuketypes,tracks,routes \
    -x transform,trk=wpt,del \
    -x track,start=20140101,stop=20150101 \
    -x transform,wpt=trk,del \
    -o gpx -F out_w.gpx
gpsbabel -i gpx -f in.gpx \
    -x nuketypes,waypoints,routes \
    -x track,start=20140101,stop=20150101 \
    -o gpx -F out_t.gpx
gpsbabel -i gpx -f out_w.gpx -f out_t.gpx -o gpx -F out.gpx

Doing this for routes 'is left as an exercise for the reader'.

answered 10 Jan '16, 23:33

ljb_nj's gravatar image

ljb_nj
659101727
accept rate: 12%

Source code available on GitHub .