posmap: Add -l/--list option
[gpstools.git] / posmap
blobd8242bee3f22ff430f245131aaeb984a57895c1e
1 #!/bin/bash
3 #=======================================================================
4 # posmap
5 # File ID: 46c65064-61d7-11e5-8232-fefdb24f8e10
7 # Plot GPS tracks around a specific waypoint.
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #=======================================================================
13 progname=posmap
14 VERSION=0.1.0
16 if test "$1" = "--version"; then
17 echo $progname $VERSION
18 exit 0
21 if test "$1" = "-h" -o "$1" = "--help"; then
22 cat <<END
24 Plot GPS tracks around a specific waypoint.
26 Usage:
28 $progname waypoint_name [radius_in_metres]
29 $progname --list
31 Options:
33 -h, --help
34 Show this help.
35 -l, --list
36 List all available waypoints.
37 --version
38 Print version information.
40 END
41 exit 0
44 name="$1"
45 if test -z "$name"; then
46 echo $progname: No waypoint name specified >&2
47 exit 1
50 if test "$name" = "-l" -o "$name" = "--list"; then
51 psql gps -c "COPY (SELECT name FROM wp) TO STDOUT;"
52 exit 0
55 radius=100
56 test -n "$2" && radius="$2"
57 echo $progname: radius = $radius metres
59 tmpfile="/tmp/.posmap.$(date +%s).$$.tmp"
60 cat <<SQL_END | psql gps >"$tmpfile"
61 COPY (
62 SELECT gpst FROM gpst
63 WHERE (coor <-> (
64 SELECT coor FROM wayp
65 WHERE name = '$1'
66 LIMIT 1
67 ) < 1.0*$radius/100000
69 ) TO STDOUT;
70 SQL_END
71 vg -2 -wd "$tmpfile"
72 rm "$tmpfile"