single day from GPX

I often carry around a GPS with me as I’m exploring, and I don’t like to remember to clear the track log, so every time I pull a GPX file off the device it’s enormous and has a bunch of extraneous data I don’t want. What I generally want is the track from the previous day. I haven’t found a completely satisfactory way to do this yet, but this comes close:

gpsbabel -t -i gpx -f in.gpx \
  -x nuketypes,waypoints,routes \
  -x track,start=20150729,stop=20150730 \
  -o gpx -F out.gpx

or you can do it directly from a garmin GPS unit plugged in via USB:

gpsbabel -t -i garmin -f usb: \
  -x nuketypes,waypoints,routes \
  -x track,start=20160525,stop=20160531 \
  -o gpx -F ~/gps/201605-rogue-river.gpx

The nuketypes filter removes all the waypoints and routes and the start and stop filters filter the GPX data by timestamp (whatever’s being used in the GPX file, which for me is UTC). What’s annoying here is that inevitably a few track points from the day will be leftovers from the previous day. I can leave them in there, but usually I’m only filtering my tracklog like this to share it with other people, so I don’t want a couple extraneous points. I can view the data, find the earliest track point that is actually correct, and use that for the time filter, but that requires an additional step using a GUI.

FWIW, taking a quick look at the file is as easy as converting to KML and using Google Earth:

ogr2ogr -f KML gpx.kml out.gpx