#!/bin/sh

# Markus Neteler 2006
# GPX -> SHAPE
# needs: http://www.gpsbabel.org
# This script is free software under the GNU General Public
# License (>=v2). Read the file COPYING that comes with GRASS
# for details (http://grass.itc.it/grass62/source/COPYING)


usage(){
 echo ""
 echo "GPX -> SHAPE conversion for easy GPS data loading into GIS"
 echo ""
 echo "Usage:"
 echo "       $0 gpxfile"
}

if [ $# -lt 1 -o "$1" = "-h" -o "$1" = "help" -o "$1" = "-help" ] ; then
        usage
        exit 1
fi

#### check if we have awk
if [ ! -x "`which gpsbabel`" ] ; then
        echo "$PROG: gpsbabel required, please install first (http://www.gpsbabel.org)" 1>&2
        exit 1
fi

GPX=$1
OUTSHAPE=`basename $GPX .gpx`.shp

# add -x to specify waypoints,routes,tracks only
gpsbabel -i gpx -f $GPX -o shape -F $OUTSHAPE
if [ $? -ne 0 ] ; then
        echo "An error occured"
        exit 1
fi
echo "Written $OUTSHAPE (depending on the gpsbabel version probably without dbf file)"
