Skip to content

Instantly share code, notes, and snippets.

@hrpunio
Created July 24, 2013 09:46
Show Gist options
  • Save hrpunio/6069281 to your computer and use it in GitHub Desktop.
Save hrpunio/6069281 to your computer and use it in GitHub Desktop.
Convert TCX (Garmin Edge) to GPX with gpsbabel
#!/bin/bash
# Convert TCX (Garmin Edge) to GPX with gpsbabel
# Usage: tcx2gpx tcx-file-name [-o gpx-file-name] -max 999
# -o -- gpx-file-name, if not given, computed from tcx-file-name (it is assumed YYYY-MM-DD*.tcx)
# -max -- produce simplified track with maximum 999 trkpoints
#
SIMPLIFY=""
if [ $# -eq 0 ]; then
echo "*** tcx2gpx tcx-file -o [gpx-file] -max 999 ***";
echo "*** If gpx-file is not given script assumes that tcx-file is as YYYY-MM-DD*.tcx ***"
echo "*** and constructs gpx-file name as YYYY-MM-DD.gpx ***"
exit 1;
fi
while test $# -gt 0; do
case "$1" in
-max) shift; COUNT="$1";;
-max*) COUNT="`echo :$1 | sed 's/^:-max//'`";;
-o) shift; OUT="$1";;
-o*) OUT="`echo :$1 | sed 's/^:-o//'`";;
*) FILE="$1";;
esac
shift
done
if [ -z "$OUT" ] ; then
gpxfile=`echo $FILE | cut -b 1-4,6-7,9-10`.gpx;
else
gpxfile="$OUT"
fi
if [ "$COUNT" != "" ] ; then SIMPLIFY="-x simplify,count=$COUNT" ; fi
if [ -e "$gpxfile" ] ; then
echo "FILE $gpxfile exists! REMOVE IT MANUALLY"
else
gpsbabel -i gtrnctr -f $FILE $SIMPLIFY -o gpx -F $gpxfile
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment