瀏覽代碼

replaced by v.in.gps

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@48151 15284696-431f-4ddb-bdfa-cd5b030d7da7
Hamish Bowman 13 年之前
父節點
當前提交
11bec3e96e
共有 3 個文件被更改,包括 0 次插入917 次删除
  1. 0 7
      scripts/v.in.garmin/Makefile
  2. 0 840
      scripts/v.in.garmin/v.in.garmin
  3. 0 70
      scripts/v.in.garmin/v.in.garmin.html

+ 0 - 7
scripts/v.in.garmin/Makefile

@@ -1,7 +0,0 @@
-MODULE_TOPDIR = ../..
-
-PGM = v.in.garmin
-
-include $(MODULE_TOPDIR)/include/Make/Script.make
-
-default: script

+ 0 - 840
scripts/v.in.garmin/v.in.garmin

@@ -1,840 +0,0 @@
-#!/bin/sh
-#
-############################################################################
-#
-# MODULE:       v.in.garmin
-#
-# AUTHOR(S):    Based on v.in.garmin.sh for GRASS 5.0 by Andreas Lange
-#                  with bug fixes by Glynn Clements and Markus Neteler
-#               Updated for GRASS 5.3 and 5.7 by Hamish Bowman
-#
-# PURPOSE:      Import GPS data from Garmin receiver into a GRASS vector map
-#
-# COPYRIGHT:    Original version (c) Andreas Lange
-#               Updates by Hamish Bowman (c) the GRASS Development Team
-#
-#############################################################################
-#
-# REQUIREMENTS:
-#      -  gpstrans from Carsten Tschach et al.
-#         At the time of writing, gpstrans is at version 0.39.
-#           get gpstrans from:
-#             http://gpstrans.sourceforge.net
-#           older versions might be found at:
-#             http://www.metalab.unc.edu/pub/Linux/science/cartography/
-#             ftp://www.mayko.com/pub/gpstrans
-#      OR
-#      - garmin-utils:  http://www.snafu.org
-#        At the time of writing, garmin-utils is at version 2.5.
-#
-#      -  unix tools: grep, cat, tac, cut, paste, awk/nawk or gawk, sed
-#      -  cs2cs from PROJ.4    http://proj.maptools.org
-# NOTES:
-#      - output may be slightly different  (millimeters) than v.in.gpsbabel
-#        due to different number of downloaded decimal places.
-
-#%Module
-#% description: Download waypoints, routes, and tracks from a Garmin GPS receiver into a vector map.
-#% keywords: vector, import, GPS
-#%End
-#%flag
-#%  key: v
-#%  description: Verbose mode
-#%end
-#%flag
-#%  key: w
-#%  description: Download Waypoints from GPS
-#%end
-#%flag
-#%  key: r
-#%  description: Download Routes from GPS
-#%end
-#%flag
-#%  key: t
-#%  description: Download Track from GPS
-#%end
-#%flag
-#%  key: p
-#%  description: Force import of track or route data as points
-#%end
-#%flag
-#%  key: u
-#%  description: Use gardump instead of gpstrans as the download program
-#%end
-#%flag
-#%  key: z
-#%  description: Import track in 3D (gardump only)
-#%end
-#%flag
-#%  key: k
-#%  description: Do not attempt projection transform from WGS84
-#%end
-#%option
-#% key: output
-#% type: string
-#% gisprompt: new,vector,vector
-#% description: Name for output vector map (omit for display to stdout)
-#% required : no
-#%end
-#%option
-#% key: port
-#% type: string
-#% description: Port Garmin receiver is connected to
-#% answer: /dev/gps
-#% required : no
-#%end
-
-if [ -z "$GISBASE" ] ; then
-    echo "You must be in GRASS GIS to run this program." >&2
-    exit 1
-fi
-
-if [ "$1" != "@ARGS_PARSED@" ] ; then
-    # save command line
-    CMDLINE="`basename $0`"
-    for arg in "$@" ; do
-	CMDLINE="$CMDLINE \"$arg\""
-    done
-    export CMDLINE
-    exec g.parser "$0" "$@"
-fi
-
-
-# set environment so that awk works properly in all languages
-unset LC_ALL
-LC_NUMERIC=C
-export LC_NUMERIC
-
-eval `g.gisenv`
-: ${GISBASE?} ${GISDBASE?} ${LOCATION_NAME?} ${MAPSET?}
-LOCATION="$GISDBASE"/"$LOCATION_NAME"/"$MAPSET"
-
-PROG=`basename $0`
-
-if [ $GIS_FLAG_U -eq 0 ] ; then
-    #### check for gpstrans
-    if [ ! -x "`which gpstrans`" ] ; then
-	g.message -e "gpstrans program not found, install it first\
-	  http://gpstrans.sourceforge.net"
-	exit 1
-    fi
-else
-    #### check for gardump from garmin-utils
-    if [ ! -x "`which gardump`" ] ; then
-	g.message -e "gardump program not found (from garmin-utils), install it first\
-	  http://www.snafu.org"
-	exit 1
-    fi
-fi
-
-#### check for cs2cs
-if [ ! -x "`which cs2cs`" ] ; then
-    g.message -e "cs2cs program not found, install it first\
-      http://proj.maptools.org"
-    exit 1
-fi
-
-#### check if we have awk
-if [ ! -x "`which awk`" ] ; then
-    g.message -e  "awk required, please install awk or gawk first"
-    exit 1
-fi
-
-
-#### setup temporary file
-TMP="`g.tempfile pid=$$`"
-if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
-    g.message -e "Unable to create temporary files"
-    exit 1
-fi
-
-#### trap ctrl-c so that we can clean up tmp
-trap 'rm -f "${TMP}"*' 2 3 15
-
-
-#### process command line arguments
-WPT=0 ; RTE=0 ; TRK=0 ; KEEP_WGS84=0; VERBOSE=0
-
-# some backwards compat verbosity
-if [ $GIS_FLAG_V -eq 1 ] ; then
-    VERBOSE=1
-    GRASS_VERBOSE=3
-    export GRASS_VERBOSE
-elif [ -n "$GRASS_VERBOSE" ] && [ "$GRASS_VERBOSE" -eq 3 ] ; then
-    VERBOSE=1
-fi
-
-if [ -n "$GIS_OPT_OUTPUT" ] ; then
-    NAME="$GIS_OPT_OUTPUT"
-    if [ $VERBOSE -eq 1 ] ; then
-	g.message message="output=$NAME"
-    fi
-fi
-if [ -n "$GIS_OPT_PORT" ] ; then
-    GPSPORT="-p$GIS_OPT_PORT"
-    if [ $VERBOSE -eq 1 ] ; then
-	g.message message="port=$GIS_OPT_PORT"
-    fi
-fi
-
-
-if [ "`expr $GIS_FLAG_W + $GIS_FLAG_R + $GIS_FLAG_T`" -gt 1 ] ; then
-    g.message -e "One feature at a time please. Use v.patch if you need to combine them."
-    rm -f "$TMP"
-    exit 1
-fi
-
-
-if [ $GIS_FLAG_W -eq 1 ] ; then
-    WPT=1
-    CREATE_POINTS=1
-fi
-if [ $GIS_FLAG_R -eq 1 ] ; then
-    RTE=1
-    CREATE_POINTS=0
-fi
-if [ $GIS_FLAG_T -eq 1 ] ; then
-    TRK=1
-    CREATE_POINTS=0
-fi
-
-if [ $GIS_FLAG_P -eq 1 ] ; then
-    CREATE_POINTS=1
-fi
-if [ $GIS_FLAG_K -eq 1 ] ; then
-    KEEP_WGS84=1
-fi
-
-if [ "`expr $WPT + $TRK + $RTE`" -eq 0 ] ; then
-    g.message -e "Must request either waypoints, route, or track."
-    rm -f "$TMP"
-    exit 1
-fi
-
-if [ $GIS_FLAG_Z -eq 1 ] &&  [ $TRK -ne 1 ] ; then
-    g.message -e "3D import is only supported for tracks so far"
-    rm -f "$TMP"
-    exit 1
-fi
-
-
-#### check that receiver is responding on $GPSPORT
-if [ $GIS_FLAG_U -eq 0 ] ; then
-    # sadly gpstrans 0.39 returns 0 after timeout.. hopefully fixed someday.
-    gpstrans "$GPSPORT" -i 1> /dev/null
-    if [ $? -ne 0 ] ; then
-	g.message -e message="Receiver on $GIS_OPT_PORT not responding, exiting"
-	rm -f "$TMP"
-	exit 1
-    fi
-elif [ $VERBOSE -eq 1 ] ; then
-    # not really needed for gardump as exit code is meaningful?
-    g.message "Testing GPS connection..."
-    gardump -u -p "$GIS_OPT_PORT" 1>&2
-    if [ $? -ne 0 ] ; then
-	g.message -e message="Receiver on $GIS_OPT_PORT not responding, exiting"
-	rm -f "$TMP"
-	exit 1
-    fi
-    g.message "GPS connection ok"
-fi
-
-#### set up projection info
-IN_PROJ="+proj=longlat +datum=WGS84"
-OUT_PROJ="`g.proj -jf`"
-PROJ_TYPE=`g.region -p | grep 'projection' | cut -f2 -d" "`
-if [ $PROJ_TYPE -eq 0 ] && [ $KEEP_WGS84 -ne 1 ] ; then
-    g.message -e "Cannot project to a XY location."
-    rm -f "$TMP"
-    exit 1
-fi
-
-
-#### receive data
-if [ $WPT -eq 1 ] ; then
-    g.message "Receiving Waypoints..."
-    if [ $GIS_FLAG_U -eq 0 ] ; then
-	gpstrans "$GPSPORT" -dw > "$TMP".gpst 2>/dev/null
-	EXITCODE=$?
-    else
-	gardump -w -p "$GIS_OPT_PORT" > "$TMP".gard
-	EXITCODE=$?
-    fi
-fi
-if [ $RTE -eq 1 ] ; then
-    g.message "Receiving Routes..."
-    if [ $GIS_FLAG_U -eq 0 ] ; then
-	gpstrans "$GPSPORT" -dr > "$TMP".gpst 2>/dev/null
-	EXITCODE=$?
-    else
-	gardump -r -p "$GIS_OPT_PORT" > "$TMP".gard
-	EXITCODE=$?
-    fi
-fi
-if [ $TRK -eq 1 ] ; then
-    g.message "Receiving Tracks..."
-    if [ $GIS_FLAG_U -eq 0 ] ; then
-	gpstrans "$GPSPORT" -dt > "$TMP".gpst 2>/dev/null
-	EXITCODE=$?
-    else
-	gardump -t -p "$GIS_OPT_PORT" > "$TMP".gard
-	EXITCODE=$?
-    fi
-fi
-#### check success/failure
-if [ "$EXITCODE" -ne 0 ] ; then
-    g.message -e "Retrieving data."
-    rm -f "${TMP}"*
-    exit 1
-fi
-
-if [ $GIS_FLAG_U -eq 0 ] ; then
-    if [ ! -e "${TMP}.gpst" ] || [ `wc -l < "${TMP}.gpst"` -le 1 ] ; then
-	g.message -w 'No Data! Exiting.'
-	rm -f "${TMP}"*
-	exit 0
-    fi
-else
-    if [ "`cat "${TMP}.gard" | grep -v '^\[' | grep -v '^#' -c`" -eq 0 ] ; then
-	g.message -w 'No Data! Exiting.'
-	rm -f "${TMP}"*
-	exit 0
-    fi
-fi
-
-if [ $GIS_FLAG_U -eq 0 ] ; then
-    #### check which projection we are working with
-    PROJ="`head -n 1 "${TMP}.gpst" | sed -e 's/Format: //' | sed -e 's/  UTC.*//'`"
-    if [ $VERBOSE -eq 1 ] ; then
-	g.message message="Coordinate format: ${PROJ}"
-    fi
-    if [ "$PROJ" != "DDD" ] ; then
-	# Why? Because v.in.ascii cannot, and cs2cs with trouble deals with DMS
-	# or DM.MM formatted input and I'm not going to start doing that sort
-	# of math in a shell script.
-	g.message -e message="Only DDD coordinates currently supported. [$PROJ]"
-	rm -f "${TMP}"*
-	exit 1
-    fi
-    IS_WGS84="`head -n 1 "$TMP".gpst | grep 'WGS 84'`"
-else
-    # gardump
-    IS_WGS84=TRUE
-fi
-
-g.message -v "Processing data..."
-
-###################################
-if [ $CREATE_POINTS -eq 1 ] ; then
-###################################
-
-    if [ $GIS_FLAG_U -eq 0 ] ; then
-        # gpstrans
-	if [ $WPT -eq 1 ] ; then
-	    cat "${TMP}.gpst" | sed -e '1d' | awk -F '\t' '{print $6 " " $5}' > "$TMP".base
-	    cat "${TMP}.gpst" | sed -e '1d' | cut -f1,2,3 | tr '\t' '|' > "$TMP".attributes
-	    ATTR_COLS='x DOUBLE PRECISION, y DOUBLE PRECISION, type VARCHAR(1), name VARCHAR(10), comments VARCHAR(40)'
-	fi
-	if [ $RTE -eq 1 ] ; then
-	    cat "${TMP}.gpst" | sed -e '1d' | grep '^W' | awk -F '\t' '{print $6 " " $5}' > "$TMP".base
-	    cat "${TMP}.gpst" | sed -e '1d' | grep '^W' | cut -f1,2,3 | tr '\t' '|' > "$TMP".attributes
-	    ATTR_COLS='x DOUBLE PRECISION, y DOUBLE PRECISION, type VARCHAR(1), name varchar(10), comments VARCHAR(40)'
-	fi
-	if [ $TRK -eq 1 ] ; then
-	    # we use uniq here as gpstrans can dupe up track points !?
-	    uniq "${TMP}.gpst" | sed -e '1d' | grep '^T' | awk -F '\t' '{print $4 " " $3}' > "$TMP".base
-	    uniq "${TMP}.gpst" | sed -e '1d' | grep '^T' | cut -f1,2 | tr '\t' '|' > "$TMP".attributes
-	    ATTR_COLS='x DOUBLE PRECISION, y DOUBLE PRECISION, type VARCHAR(1), localtime VARCHAR(40)'
-	    HAVE_ALT=FALSE
-	fi
-    else
-	# gardump from garmin-utils
-	if [ $WPT -eq 1 ] || [ $RTE -eq 1 ] ; then
-	    # **n [route name]
-	    # lat long [A:alt] [S:sym] [D:display] [I:id] [C:cmnt] [W:wpt info] [L:link]
-	    grep -E -v '^\[|^#|^\*\*' "${TMP}.gard" | awk '{print $2 " " $1}' > "$TMP".base
-
-	    ROUTE_NUM=""
-	    ROUTE_NAME=""
-	    # this will be very slow :-(  maybe could be written as an awk script?
-	    while read LINE ; do
-		unset A_VAL S_VAL D_VAL I_VAL C_VAL W_VAL L_VAL
-		if [ `echo "$LINE" | grep -E -c '^\[|^#'` -eq 1 ] ; then
-		    continue
-		fi
-		if [ `echo "$LINE" | grep -c '^\*\*'` -eq 1 ] ; then
-		   ROUTE_NUM=`echo "$LINE" | cut -f1 -d' ' | sed -e 's/^\*\*//'`
-		   ROUTE_NAME=`echo "$LINE" | grep ' ' | cut -f2- -d' '`
-		   continue
-		fi
-		A_VAL=`echo "$LINE" | sed -e 's/ [ASDICWL]:/\n&/g' | grep '^ A:' | sed -e 's/^ A://'`
-		S_VAL=`echo "$LINE" | sed -e 's/ [ASDICWL]:/\n&/g' | grep '^ S:' | sed -e 's/^ S://'`
-		D_VAL=`echo "$LINE" | sed -e 's/ [ASDICWL]:/\n&/g' | grep '^ D:' | sed -e 's/^ D://'`
-		I_VAL=`echo "$LINE" | sed -e 's/ [ASDICWL]:/\n&/g' | grep '^ I:' | sed -e 's/^ I://'`
-		C_VAL=`echo "$LINE" | sed -e 's/ [ASDICWL]:/\n&/g' | grep '^ C:' | sed -e 's/^ C://'`
-		W_VAL=`echo "$LINE" | sed -e 's/ [ASDICWL]:/\n&/g' | grep '^ W:' | sed -e 's/^ W://'`
-		L_VAL=`echo "$LINE" | sed -e 's/ [ASDICWL]:/\n&/g' | grep '^ L:' | sed -e 's/^ L://'`
-### hack for broken v.in.ascii scan (last col must not be empty for all records)
-###  poi_link column should be INTEGER type.
-		if [ -z "$L_VAL" ] ; then
-		   L_VAL=NULL
-		fi
-
-		if [ $WPT -eq 1 ] ; then
-		    echo "$A_VAL|$S_VAL|$D_VAL|$I_VAL|$C_VAL|$W_VAL|$L_VAL" >> "$TMP".attributes
-		elif [ $RTE -eq 1 ] ; then
-		    echo "$ROUTE_NUM|$ROUTE_NAME|$A_VAL|$S_VAL|$D_VAL|$I_VAL|$C_VAL|$W_VAL|$L_VAL" >> "$TMP".attributes
-		fi
-	    done < "${TMP}.gard"
-
-	    if [ $WPT -eq 1 ] ; then
-		ATTR_COLS='x DOUBLE PRECISION, y DOUBLE PRECISION, altitude DOUBLE PRECISION, symbol INTEGER, smbl_flag INTEGER, name VARCHAR(15), comments VARCHAR(50), poi_code VARCHAR(40), poi_link VARCHAR(4)'
-	    elif [ $RTE -eq 1 ] ; then
-		ATTR_COLS='x DOUBLE PRECISION, y DOUBLE PRECISION, route_num INTEGER, route_name VARCHAR(40), altitude DOUBLE PRECISION, symbol INTEGER, smbl_flag INTEGER, name VARCHAR(15), comments VARCHAR(50), poi_code VARCHAR(40), poi_link VARCHAR(4)'
-	    fi
-	fi
-
-	if [ $TRK -eq 1 ] ; then
-	    # [yyyy-mm-dd hh:mm:ss] lat long [alt] [start]
-	    unset HAVE_ALT
-	    # some tracks don't have time/date, so we have to decide on the fly
-	    grep -v '^\[\|^#\|^Track:' "${TMP}.gard" | \
-	      awk '{ if ( $0 ~ /..:..:../) {
-			print $4 " " $3
-		     } else {
-			print $2 " " $1
-		     }
-		   }' > "$TMP".base
-
-	    grep -v '^\[\|^#\|^Track:' "${TMP}.gard" | \
-	      awk '{ if ( $0 ~ /..:..:../) {
-			print $1 "|" $2 "|" $5 "|" $6
-		     } else {
-			print "||" $3 "|" $4
-		     }
-		   }' > "$TMP.attr"
-
-	    # check if there is any altitude data
-	    if [ `cut -f3 -d'|' "$TMP.attr" | grep -c 'start'` -ge 1 ] ; then
-		HAVE_ALT=FALSE
-		ATTR_COLS='x DOUBLE PRECISION, y DOUBLE PRECISION, gmt_date VARCHAR(10), gmt_time VARCHAR(8), new_track VARCHAR(5)'
-		if [ $GIS_FLAG_Z -eq 1 ] ; then
-		    g.message -w "No altitude data found, creating 2D vector map"
-		fi
-	    else
-		HAVE_ALT=TRUE
-		ATTR_COLS='x DOUBLE PRECISION, y DOUBLE PRECISION, gmt_date VARCHAR(10), gmt_time VARCHAR(8), altitude DOUBLE PRECISION, new_track VARCHAR(5)'
-	    fi
-
-	    # check if there is any track name data
-	    if [ `grep -c '^Track:' "${TMP}.gard"` -ge 1 ] ; then
-		ATTR_COLS="$ATTR_COLS, track_name VARCHAR(15)"
-
-		# create data for track name column
-# need extra if(TRK) else NULL stuff for v.in.ascii empty last column bug
-		grep -v '^\[\|^#' "${TMP}.gard" | awk \
-		  '/^Track:/ {TRK=$0; sub(/^Track: /, "", TRK)} ;
-		   /^[-0-9]/ {if(TRK) {print TRK} else {print "NULL"}}' > "$TMP.trackname"
-		paste -d'|' "$TMP.attr" "$TMP.trackname"  > "$TMP.attributes"
-	    else
-		cp "$TMP.attr" "$TMP.attributes"
-	    fi
-	fi
-    fi
-
-    #### reproject if needed (only consider 2D)
-    if [ -z "$IS_WGS84" ] || [ $KEEP_WGS84 -eq 1 ] ; then
-	g.message "No projection transformation performed"
-	cp "${TMP}.base" "${TMP}.P_base"
-    else
-	g.message "Attempting waypoint projection transform with cs2cs..."
-	cs2cs -f %.7f $IN_PROJ +to $OUT_PROJ < "${TMP}.base" > "${TMP}.P_base"
-	EXITCODE=$?
-	# check if transform REALLY worked (e.g. grid file not found)
-	BAD_PTS="`grep -c "^\*" "${TMP}.P_base"`"
-	if [ "$BAD_PTS" -gt 0 ] ; then
-	    g.message message=""
-	    g.message -w "$BAD_PTS point(s) failed reprojection."
-	    EXITCODE=1
-	fi
-	if [ $EXITCODE -ne 0 ] ; then
-	    g.message -w "Projection transform failed, retaining WGS84"
-	    g.message message=""
-	    cp -f "${TMP}.base" "${TMP}.P_base"
-	fi
-    fi
-    cat "${TMP}.P_base" | awk '{print $1 "|" $2}' > "${TMP}.vertices"
-
-    #### and put back together
-    # wpt list:   x|y|    W   MOB    04-OCT-03 08:07
-    paste -d"|" "$TMP".vertices "$TMP".attributes > "$TMP".asc
-
-
-    if [ -z "$NAME" ] ; then
-	g.message "ASCII file redirected to stdout"
-	cat "${TMP}.asc" 2> /dev/null
-    else
-	#### import into new ascii points file
-	if [ $WPT -eq 1 ] ; then
-	    g.message "Importing Waypoints..."
-	    v.in.ascii input="${TMP}.asc" output="$NAME" cat=0 columns="$ATTR_COLS" --quiet
-	    EXITCODE=$?
-	fi
-	if [ $RTE -eq 1 ] ; then
-	    g.message "Importing Routes as points..."
-	    v.in.ascii input="${TMP}.asc" output="$NAME" cat=0 columns="$ATTR_COLS"
-	    EXITCODE=$?
-	fi
-	if [ $TRK -eq 1 ] ; then
-	    if [ $GIS_FLAG_Z -eq 1 ] && [ "$HAVE_ALT" = "TRUE" ] ; then
-		g.message "Importing Track as 3D points..."
-		v.in.ascii input="${TMP}.asc" output="$NAME" cat=0 columns="$ATTR_COLS" -z z=5
-		EXITCODE=$?
-	    else
-		g.message "Importing Track as points..."
-		v.in.ascii input="${TMP}.asc" output="$NAME" cat=0 columns="$ATTR_COLS"
-		EXITCODE=$?
-	    fi
-	fi
-
-	if [ $EXITCODE -ne 0 ] ; then
-	    g.message -e "While importing data with v.in.ascii"
-	    rm -f "${TMP}"*
-	    exit 1
-	fi
-
-    fi
-
-#####################
-else # CREATE_LINES
-#####################
-
-    if [ $GIS_FLAG_U -eq 0 ] ; then
-	#gpstrans
-
-	#### prepare line components
-	if [ $RTE -eq 1 ] ; then
-	    # add vertex counts
-	    cat "${TMP}.gpst" | sed -e '1d' | tac | awk 'BEGIN { FS="\t" ; R=0 } \
-		$1=="W" { printf(" %.7f %.7f\n", $6, $5) ; ++R } ; \
-		$1=="R" { printf("L %d 1\n", R) ; R=0 } END {;}' | tac > "${TMP}.base"
-
-	    # create attr table: cat(int), id number(int 0-19), name varchar(16+), starting_wpt(varchar 10)
-	    cat "${TMP}.gpst" | grep '^R' | cut -f2,3 | grep -n '^' | \
-		sed -e 's/:/\t/' > "${TMP}.route_ids"
-	    cat "${TMP}.gpst" | sed -e '1d' | grep '^R' -A 1 | grep '^W' | cut -f2 > "${TMP}.route_start"
-	    paste "${TMP}.route_ids" "${TMP}.route_start" > "${TMP}.route_atts"
-	    ATTR_FILE="${TMP}.route_atts"
-	    ATTR_COLS='cat INT, route_id INT, name VARCHAR(20), start_wpt VARCHAR(10)'
-
-	elif [ $TRK -eq 1 ] ; then
-	    # add vertex counts
-	    cat "${TMP}.gpst" | sed -e '1d' | tac | awk 'BEGIN { FS="\t" ; R=0 } \
-		$1=="T" { printf(" %.7f %.7f\n", $4, $3) ; ++R } ; \
-		$1=="" { printf("L %d 1\n", R) ; R=0 } END {;}' | tac > "${TMP}.base"
-
-	    # create attr table: cat(int), start_time varchar(40), start_lat(double precision), start_lon(double precision), \
-	    #			    end_time varchar(40), end_lat(double precision), end_lon(double precision)
-	    cat "${TMP}.gpst" | sed -e '1d' | grep '^$' -B 1 | grep '^T' | cut -f2,3,4 > "${TMP}.end_time"
-	    cat "${TMP}.gpst" | grep '^T' | tail -n 1 | cut -f2,3,4 >> "${TMP}.end_time"
-	    cat "${TMP}.gpst" | sed -e '1d' | grep '^$' -A 1 | grep '^T' | cut -f2,3,4 | \
-		grep -n '^' | sed -e 's/:/\t/'  > "${TMP}.start_time"
-	    paste "${TMP}.start_time" "${TMP}.end_time" > "${TMP}.track_atts"
-	    ATTR_FILE="${TMP}.track_atts"
-	    ATTR_COLS='cat INT, start_time VARCHAR(40), start_lat DOUBLE PRECISION, start_lon DOUBLE PRECISION, end_time VARCHAR(40), end_lat DOUBLE PRECISION, end_lon DOUBLE PRECISION'
-	fi
-
-    else
-	# gardump
-	if [ $RTE -eq 1 ] ; then
-	    # add vertex counts
-	    grep -v '^\[\|^#' "${TMP}.gard" | tac | awk 'BEGIN { R=0 } \
-		/^[-0-9]/ { printf(" %.7f %.7f\n", $2, $1) ; ++R } ; \
-		/^\*\*/ { printf("L %d 1\n", R) ; R=0 } END {;}' | tac > "${TMP}.base"
-
-	    # create attr table: cat(int), id number(int 0-19), name varchar(40), starting_wpt(varchar 15)
-	    # grep -n is to insert cat number, starting from 1. (route numbers start from 0)
-	    grep '^\*\*' "${TMP}.gard" | sed -e 's/^\*\*//' -e 's/ /|/' \
-	       | grep -n '^' | sed -e 's/:/|/' > "${TMP}.route_ids"
-
-	    grep -A 1 '^\*\*' "${TMP}.gard" | grep -E -v '^\*\*|^--' | \
-	      sed -e 's/.* I://' | awk '{print $1}' > "${TMP}.route_start"
-
-	    paste -d'|' "${TMP}.route_ids" "${TMP}.route_start" > "${TMP}.route_atts"
-
-	    ATTR_FILE="${TMP}.route_atts"
-	    ATTR_COLS='cat int, route_id INT, name VARCHAR(40), start_wpt VARCHAR(15)'
-
-	elif [ $TRK -eq 1 ] ; then
-	    # add vertex counts
-	    # some tracks don't have time/date, so we have to decide on the fly
-	    grep -v '^\[\|^#\|^Track:' "${TMP}.gard" | tac | awk 'BEGIN { R=0 } \
-	    ! /start/ {
-	      if($0 ~ /..:..:../ ) { printf(" %.7f %.7f\n", $4, $3) }
-	      else { printf(" %.7f %.7f\n", $2, $1) }
-	      ++R
-	    } ;
-
-	    /start/ {
-	      if($0 ~ /..:..:../ ) { printf(" %.7f %.7f\nL %d 1\n", $4, $3, R+1) }
-	      else { printf(" %.7f %.7f\nL %d 1\n", $2, $1, R+1) }
-	      R=0
-	    }
-	    END {;}' | tac > "${TMP}.base"
-
-	    # create attr table: cat(int), \
-	    #  start_time varchar(40), start_lat(double precision), start_lon(double precision), \
-	    #  end_time varchar(40), end_lat(double precision), end_lon(double precision)
-	    #  [track_name varchar(15)]
-
-	    # - format time string in ISO 8601 format
-	    # - some tracks have timestamps some don't
-	    # - use grep -n to add "line number: string" for cat as track nums start as 0
-
-	    # crop out start times
-	    grep 'start$' "${TMP}.gard" | \
-	      awk '{ if ( $0 ~ /..:..:../ ) {
-			print $1 "T" $2 "Z|" $3 "|" $4
-		     } else {
-			print "|" $1 "|" $2
-		     }
-		   }' | grep -n '^' | sed -e 's/:/|/' > "${TMP}.start_time"
-
-	    # find and crop out end times. if only 1 pt in trk, use start as end time
-	    grep -v '^#\|^\[\|^Track:' "${TMP}.gard" | grep -B 1 'start$' | \
-	      grep -v '^--' | awk 'BEGIN { FIRST=1 } \
-		/start/ {
-		  if (FIRST != 1) { print TIME "|" LAT "|" LON } else { FIRST=0 } ;
-		  if ( $0 ~ /..:..:../ ) {
-		    TIME=$1 "T" $2 "Z"; LAT=$3; LON=$4
-		  } else {
-		    TIME=""; LAT=$1; LON=$2
-		  }
-		} ;
-		! /start/ {
-		  if ( $0 ~ /..:..:../ ) {
-		    TIME=$1 "T" $2 "Z"; LAT=$3; LON=$4
-		  } else {
-		    TIME=""; LAT=$1; LON=$2
-		  }
-		}' > "${TMP}.end_time"
-
-	    # get time & coord of final point
-	    grep -B 1 'end transfer' "${TMP}.gard" | grep '^[0-9]' | awk \
-	       '{ if ( $0 ~ /..:..:../ ) {
-		    print $1 "T" $2 "Z|" $3 "|" $4
-		  } else {
-		    print "|" $1 "|" $2
-		  }
-		}' >> "${TMP}.end_time"
-
-	    ATTR_COLS='cat INT, start_time VARCHAR(40), start_lat DOUBLE PRECISION, start_lon DOUBLE PRECISION, end_time VARCHAR(40), end_lat DOUBLE PRECISION, end_lon DOUBLE PRECISION'
-
-	    # check if there is any track name data
-	    unset HAVE_TRACK_NAME
-	    if [ `grep -c '^Track:' "${TMP}.gard"` -ge 1 ] ; then
-		HAVE_TRACK_NAME=TRUE
-		ATTR_COLS="$ATTR_COLS, track_name VARCHAR(15)"
-
-		# extract data for track name column
-		grep -v '^\[\|^#' "${TMP}.gard" | grep '^Track:\|start' | awk \
-		  '/^Track:/ {TRK=$0; sub(/^Track: /, "", TRK)} ;
-		   /^[-0-9]/ {print TRK}' > "$TMP.trackname"
-		paste -d'|' "${TMP}.start_time" "${TMP}.end_time" "$TMP.trackname" > "${TMP}.track_atts"
-	    else
-		HAVE_TRACK_NAME=FALSE
-		paste -d'|' "${TMP}.start_time" "${TMP}.end_time" > "${TMP}.track_atts"
-	    fi
-	    ATTR_FILE="${TMP}.track_atts"
-	fi
-    fi
-
-    #### reproject if needed
-    if [ -z "$IS_WGS84" ] || [ $KEEP_WGS84 -eq 1 ] ; then
-	g.message "No projection transformation performed"
-	cat "${TMP}.base" | awk 'BEGIN {;} $1=="L" { print } ; \
-	    $1!="L" { printf(" %.7f %.7f\n", $1, $2) } END {;}' > "${TMP}.P_base"
-    else
-	g.message "Attempting waypoint projection transform with cs2cs..."
-	cs2cs -tL -f %.7f $IN_PROJ +to $OUT_PROJ < "${TMP}.base" > "${TMP}.P_mid"
-	EXITCODE=$?
-	# check if transform REALLY worked (e.g. grid file not found)
-	BAD_PTS="`grep -c "^\*" "${TMP}.P_mid"`"
-	if [ "$BAD_PTS" -gt 0 ] ; then
-	    g.message message=""
-	    g.message -w "$BAD_PTS vertices failed reprojection."
-	    EXITCODE=1
-	fi
-	if [ $EXITCODE -ne 0 ] ; then
-	    g.message -w "Projection transform failed, retaining WGS84"
-	    g.message message=""
-	    cat "${TMP}.base" | awk 'BEGIN {;} $1=="L" { print } ; \
-		$1!="L" { printf(" %.7f %.7f\n", $1, $2) } END {;}' > "${TMP}.P_base"
-	else
-	    cat "${TMP}.P_mid" | awk 'BEGIN {;} $1=="L" { print } ; \
-		$1!="L" { printf(" %.7f %.7f\n", $1, $2) } END {;}' > "${TMP}.P_base"
-	fi
-    fi
-
-    # add category numbers
-    cat "${TMP}.P_base" | awk 'BEGIN { FS=" " ; R=0 } \
-	$1=="L" { printf(" 1 %d\nL %d 1\n", R, $2) ; ++R } ; \
-	$1!="L" { print } END { printf(" 1 %d\n", R) }' | sed -e '1d' > "${TMP}.P_baseC"
-
-    # add z for 3D maps
-    unset HAVE_ALT
-    if [ $GIS_FLAG_Z -eq 1 ] ; then
-	# check if there is any altitude data
-	if [ `grep -v '^\[\|^#\|^Track:' "${TMP}.gard" | tr -s ' ' '|' | cut -f6 -d'|' | grep -c start` -ge 1 ] ; then
-	    HAVE_ALT=TRUE
-	else
-	    HAVE_ALT=FALSE
-	    if [ $GIS_FLAG_Z -eq 1 ] ; then
-		g.message -w "No altitude data found, creating 2D vector map"
-	    fi
-	fi
-    else
-	HAVE_ALT=FALSE
-    fi
-
-    if [ "$HAVE_ALT" = "TRUE" ] ; then
-	# cut out altitude data and add blank lines between track lines
-	grep -v '^\[\|^#\|^Track:' "${TMP}.gard" | tac | \
-	  awk '{ if($0 ~ /..:..:../ ) {
-		   print $5 " " $6
-		 } else {
-		   print $3 " " $4
-		 }
-	       }' | sed -e 's/ start/\n/' -e 's/ $//' | tac > "${TMP}.alt"
-
-	paste -d' ' "${TMP}.P_base" "${TMP}.alt" > "${TMP}.P_baseZ"
-    else
-	cp "${TMP}.P_base" "${TMP}.P_baseZ"
-    fi
-
-    # add category numbers
-    cat "${TMP}.P_baseZ" | awk 'BEGIN { FS=" " ; R=0 } \
-	$1=="L" { printf(" 1 %d\nL %d 1\n", R, $2) ; ++R } ; \
-	$1!="L" { print } END { printf(" 1 %d\n", R) }' | sed -e '1d' \
-	  > "${TMP}.P_baseC"
-
-
-    #### create digit header
-    cat << EOF > "${TMP}.dig"
-ORGANIZATION: GRASSroots organization
-DIGIT DATE:   `date "+%Y/%m/%d"`
-DIGIT NAME:   $PROG
-MAP NAME:     $NAME
-MAP DATE:     `date +%Y`
-MAP SCALE:    1
-OTHER INFO:   Imported by `echo $USER@$HOSTNAME`
-ZONE:         0
-MAP THRESH:   0
-VERTI:
-EOF
-
-    #### merge in vertices
-    cat "${TMP}.P_baseC" >> "${TMP}.dig"
-
-    #### if no name for vector file given, cat to stdout
-    if [ -z "$NAME" ] ; then
-	g.message "ASCII file redirected to stdout"
-	cat "${TMP}.dig" 2> /dev/null
-    else
-	#### import to binary vector file
-	if [ $GIS_FLAG_Z -eq 1 ] && [ "$HAVE_ALT" = "TRUE" ] ; then
-	    ZFLAG="-z"
-	else
-	    ZFLAG=""
-	fi
-
-	g.message "Importing with v.in.ascii..."
-	v.in.ascii format=standard output="$NAME" input="${TMP}.dig" $ZFLAG
-
-	#### check success/failure
-	if [ $? -eq 0 ] ; then
-	    g.message -v message="Line vector <$NAME> successfully created"
-	else
-	    g.message -e "An error occured creating <$NAME>, please check"'!'
-	    rm -f "${TMP}"*
-	    exit 1
-	fi
-
-	# create db links if they don't exist
-	db.connect -c
-	DRIVER="`db.connect -p | grep '^driver:' | cut -f2 -d:`"
-	if [ "$DRIVER" = "dbf" ] && [ ! -d "$LOCATION/dbf/" ] ; then
-	    mkdir "$LOCATION/dbf/"
-	fi
-
-	g.message "Creating new table.."
-	echo "CREATE TABLE $NAME ($ATTR_COLS)" | db.execute
-	if [ $? -ne 0 ] ; then
-	    g.message -e "Map created but failed to create database table."
-	    rm -f "${TMP}"*
-	    exit 1
-	fi
-
-
-	g.message "Populating table with attributes.."
-# echo "COPY $NAME FROM '$ATTR_FILE'" | db.execute
-
-# "COPY table FROM 'filename.txt'" does not work for DBF and there is no
-#   db.in.ascii yet, so we use a hack...
-
-### <hack>
-	if [ $RTE -eq 1 ] ; then
-	    # =>  INSERT INTO $NAME VALUES (2, 1, 'AB', 'B')
-	    awk -F'|' -v NAME="$NAME" \
-	      '{ printf("INSERT INTO %s VALUES (%d, %d, ^%s^, ^%s^);\n", NAME, $1, $2, $3, $4) }' \
-	      "$ATTR_FILE" | tr '^' \' > "$ATTR_FILE"_exe
-	fi
-	if [ $TRK -eq 1 ] ; then
-	    # =>  INSERT INTO $NAME VALUES (,,,,,);
-	    if [ "$HAVE_TRACK_NAME" = "TRUE" ] ; then
-	    		awk -F'|' -v NAME="$NAME" \
-		  '{ printf("INSERT INTO %s VALUES (%d, ^%s^, %.7f, %.7f, ^%s^, %.7f, %.7f, ^%s^);\n", \
-		     NAME, $1, $2, $3, $4, $5, $6, $7, $8) }' "$ATTR_FILE" | \
-		  tr '^' \' > "$ATTR_FILE"_exe
-	    else
-		awk -F'|' -v NAME="$NAME" \
-		  '{ printf("INSERT INTO %s VALUES (%d, ^%s^, %.7f, %.7f, ^%s^, %.7f, %.7f);\n", \
-		     NAME, $1, $2, $3, $4, $5, $6, $7) }' "$ATTR_FILE" | \
-		  tr '^' \' > "$ATTR_FILE"_exe
-	    fi
-	fi
-
-	db.execute input="$ATTR_FILE"_exe
-	if [ $? -ne 0 ] ; then
-	    g.message -e "Map created but failed to populate database table."
-	    # need to connect it before we can delete it. :-/
-	    v.db.connect map="$NAME" table="$NAME" 2> /dev/null
-	    v.db.droptable -f map=$NAME --quiet
-	    rm -f "${TMP}"*
-	    exit 1
-	fi
-### </hack>
-
-	g.message "Connecting attribute table to vector file..."
-	v.db.connect map="$NAME" table="$NAME"
-    fi
-
-fi  # if CREATE_POINTS or CREATE_LINES
-
-
-# list column names
-if [ $VERBOSE -eq 1 ] && [ -n "$NAME" ] ; then
-    g.message message="<$NAME> columns:"
-    db.columns "$NAME"
-fi
-
-# write cmd history:
-v.support map="$NAME" cmdhist="${CMDLINE}"
-
-#### clean up the mess
-\rm -f "${TMP}"*
-
-#### end
-g.message "Done."
-
-exit 0

+ 0 - 70
scripts/v.in.garmin/v.in.garmin.html

@@ -1,70 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em>v.in.garmin</em> allows the user to import waypoint, route, and track
- data from a locally connected Garmin GPS receiver via the 
-<em><a href="http://gpstrans.sourceforge.net">gpstrans</a></em>
- program by Carsten Tschach or the
-<em><a href="http://www.snafu.org">gardump</a></em>
- program by Marc Hyman. 
-
-<h2>NOTES</h2>
-If the GPS is set up to output WGS84 Lat/Lon, <em>v.in.garmin</em> will
-attempt to automatically transform the coordinates to the current projection.
-In all other cases, no checks are performed for datum, projection and format of data.
-You must check for yourself that your receiver, gpstrans and GRASS
-use the same map datum and projection.
-The automatic transform may be skipped by using the <b>-k</b> flag.
-
-<p>
-Route and Track data may be uploaded as points by using the <em>-p</em> flag, 
-otherwise they will be imported as a line. You can run <em>v.in.garmin</em>
-multiple times and merge the line and point vectors with the <em>v.patch</em>
-command if you want, but take care when merging dissimilar attribute tables.
-
-<p>
-Future versions of GRASS will use <em>gardump</em> as the default download
-program. It can talk to newer Garmin GPSs, while <em>gpstrans</em> seems to
-be mostly abandoned these days and only works with older GPSs. The current
-version of <em>gardump</em> (ver 2.5) will not yet talk to USB-only GPSs, but
-you can try the <em>v.in.gpsbabel</em> module for those. The <em>gardump</em>
-code has been tested with an older Garmin GPS 45 and a newer GPS V and is
-expected to work with everything in between.
-
-<p>
-Before running <em>v.in.garmin</em>, <em>gpstrans</em> should be set up 
-to output WGS84 latitude-longitude, as follows: <br>
-<tt>
-$ <b>gpstrans -s</b><br>
-datum:  100 (WGS84)<br>
-format: 2 - lat/lon  ddd.ddddd<br>
-</tt>
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="db.execute.html">db.execute</a>,
-<a href="v.in.ascii.html">v.in.ascii</a>,
-<a href="v.in.gpsbabel.html">v.in.gpsbabel</a>,
-<a href="v.db.connect.html">v.db.connect</a>,
-<a href="v.patch.html">v.patch</A>
-</em>
-
-<p>
-<a href="http://gpstrans.sourceforge.net">gpstrans</a> manual<br>
-<a href="http://www.snafu.org">gardump</a> from the "garmin-utils" package<br>
-cs2cs from <a href="http://trac.osgeo.org/proj/">PROJ.4</a><br>
-The <tt>awk</tt> user manual
-
-<p>
-<h2>AUTHORS</h2>
-Based on <em>v.in.garmin.sh</em> for GRASS 5.0 by Andreas Lange
-<br>&nbsp;&nbsp;&nbsp;&nbsp;
-with bug fixes by Glynn Clements and Markus Neteler
-<br>Rewritten for GRASS 5.3 and 5.7 by Hamish Bowman
-<br><tt>gardump</tt> and 3D track support by Hamish Bowman
-<p>
-gpstrans was written by Carsten Tschach<br>
-gardump was written by Marc Hyman<br>
-
-<p>
-<i>Last changed: $Date$</i>