Skip to content

Instantly share code, notes, and snippets.

@NickCharsley
Forked from hrpunio/tcx2gpx
Created February 7, 2016 17:35
Show Gist options
  • Save NickCharsley/fe03e63985823667c48b to your computer and use it in GitHub Desktop.
Save NickCharsley/fe03e63985823667c48b to your computer and use it in GitHub Desktop.

Revisions

  1. @hrpunio hrpunio created this gist Jul 24, 2013.
    41 changes: 41 additions & 0 deletions tcx2gpx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    #!/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