[GRASS-SVN] r53703 - in grass-addons/grass6/display: . d.hyperlink
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Nov 6 06:11:00 PST 2012
Author: neteler
Date: 2012-11-06 06:10:59 -0800 (Tue, 06 Nov 2012)
New Revision: 53703
Added:
grass-addons/grass6/display/d.hyperlink/
grass-addons/grass6/display/d.hyperlink/Makefile
grass-addons/grass6/display/d.hyperlink/d.hyperlink
grass-addons/grass6/display/d.hyperlink/description.html
Log:
Eric Patton: added here from ftp://gsca.nrcan.gc.ca/outgoing/Patton/Grass/Scripts/d.hyperlink.tar.bz2
Added: grass-addons/grass6/display/d.hyperlink/Makefile
===================================================================
--- grass-addons/grass6/display/d.hyperlink/Makefile (rev 0)
+++ grass-addons/grass6/display/d.hyperlink/Makefile 2012-11-06 14:10:59 UTC (rev 53703)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = d.hyperlink
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script
Added: grass-addons/grass6/display/d.hyperlink/d.hyperlink
===================================================================
--- grass-addons/grass6/display/d.hyperlink/d.hyperlink (rev 0)
+++ grass-addons/grass6/display/d.hyperlink/d.hyperlink 2012-11-06 14:10:59 UTC (rev 53703)
@@ -0,0 +1,325 @@
+#! /bin/bash
+#
+############################################################################
+#
+# MODULE: d.hyperlink for Grass 6.0/6.1
+#
+# AUTHOR(S): Eric Patton
+#
+# PURPOSE: To allow display of hyperlinked documents from a vector
+# attribute table.
+#
+# COPYRIGHT: (C) 2006 by the GRASS Development Team
+#
+# This program is free software under the GNU General Public
+# License (>=v2). Read the file COPYING that comes with GRASS
+# for details.
+#
+# Last Modified: March 19, 2006
+#
+#############################################################################
+
+#%Module
+#% description: Allows the interactive display of hyperlinked documents from a vector attribute table.
+#%END
+
+#%flag
+#% key: c
+#% description: list columns in attached database
+#%END
+
+#%flag
+#% key: d
+#% description: list directories in Location's MAPSET
+#%END
+
+#%flag
+#% key: i
+#% description: enable interactive mode (uses d.what.vect)
+#%END
+
+#%flag
+#% key: p
+#% description: print command-line parameters given (for testing)
+#%END
+
+#%option
+#% key: map
+#% type: string
+#% gisprompt: old,vector,vector
+#% description: vector map to load hyperlink from
+#% required : no
+#%END
+
+#%option
+#% key: linkdir
+#% type: string
+#% description: directory containing hyperlinks
+#% answer: hyperlinks
+#% required: no
+#%END
+
+#%option
+#% key: layer
+#% type: integer
+#% description: layer of the linked table
+#% answer: 1
+#% required : no
+#%END
+
+#%option
+#% key: column
+#% type: string
+#% description: attribute table column containing document to be hyperlinked
+#% answer: hyperlink
+#% required : no
+#%END
+
+#%option
+#% key: where
+#% type: string
+#% description: WHERE conditions of SQL statement without 'where' keyword. (Ex: cat=26 or Station_ID=12)
+#% required: no
+#%END
+
+#%option
+#% key: viewer
+#% type: string
+#% description: image viewer to open hyperlinks
+#% options: eog,gimp,gpdf,gthumb,inkscape
+#% answer: gthumb
+#% required: no
+#%END
+
+SCRIPT=`basename $0`
+
+if [ -z "$GISBASE" ] ; then
+ echo "You must be in GRASS GIS to run this program."
+ exit 1
+fi
+
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+ exec g.parser "$0" "$@"
+fi
+
+# Capture CTRL-C and similar breaks.
+trap 'echo -e "\n\nUser break! Exiting.\n" ; exit 1' 2 3 15
+
+# Check if we have awk.
+if [ ! -x "`which awk`" ] ; then
+ echo "$SCRIPT: awk required, please install awk or gawk first" 2>&1
+ exit 1
+fi
+
+# Setting environment, so that awk works properly in all languages.
+unset LC_ALL
+export LC_NUMERIC=C
+
+# Capture Location, Mapset, etc. to feed directory path for image viewer.
+eval `g.gisenv`
+: ${GISBASE?} ${GISDBASE?} ${LOCATION_NAME?} ${MAPSET?}
+LOCATION=$GISDBASE/$LOCATION_NAME/$MAPSET
+
+FOLDER="$LOCATION/$GIS_OPT_LINKDIR"
+INPUT="$GIS_OPT_MAP"
+COLUMN="$GIS_OPT_COLUMN"
+LAYER="$GIS_OPT_LAYER"
+VIEWER="$GIS_OPT_VIEWER"
+
+# Get current database connection parameters from db.connect:
+DRIVER=`db.connect -p | grep 'driver' | awk -F: '{print $2}'`
+DATABASE=`db.connect -p | grep 'database' | awk -F: '{print $2}'`
+TABLE="`v.db.connect -g "$INPUT" | grep $LAYER | cut -f2 -d' '`"
+
+# Provide driectory listing in MAPSET for -d flag.
+if [ "$GIS_FLAG_d" -eq 1 ] ; then
+ echo ""
+ echo "======================================="
+ echo "Directory listing for MAPSET $MAPSET:"
+ echo "======================================="
+ echo ""
+ ls -l $LOCATION | grep '^d' | awk '{print $8}'
+ exit 0
+fi
+
+# Fetch the input vector map.
+if [ -n "$INPUT" ] ; then
+eval `g.findfile element=vector mapset=$MAPSET file=$INPUT`
+ if [ ! "$file" ] ; then
+ echo ""
+ echo "$SCRIPT: Input map not found\n" 2>&1
+ exit 1
+ fi
+
+ else
+ echo "$SCRIPT: Please enter an input vector.\n" 2>&1
+ exit 1
+fi
+
+# Provide list of columns in connected table for -c flag.
+if [ "$GIS_FLAG_c" -eq 1 ] ; then
+ db.columns table=$TABLE driver=$DRIVER database=$DATABASE
+ exit 0
+fi
+
+# Provide command-line parameters for -p flag. For testing only...
+if [ "$GIS_FLAG_p" -eq 1 ] ; then
+ echo ""
+ echo "================================================================="
+ echo "Input is: $INPUT"
+ echo "Attribute table is: $TABLE"
+ echo "Hyperlink folder is: $FOLDER"
+ echo "Link Column is: $COLUMN"
+ echo "Layer is: $LAYER"
+ echo "================================================================="
+ echo ""
+ exit 0
+fi
+
+
+# Check if the hyperlink folder is a valid directory.
+if [ ! -d "$FOLDER" ] ; then
+ echo ""
+ echo -e "$SCRIPT: Specified link folder is not a directory. Exiting." 2>&1
+ exit 1
+fi
+
+
+# Check and see if an attribute table is connected on given layer
+# FIXME: This test fails if map is in another mapset!!! (eg map at othermapset).
+if [ -z "$TABLE" ] ; then
+ echo "\n$SCRIPT: No table connection for layer $LAYER on vector $INPUT."
+ echo "Use v.db.connect first."
+ exit 1
+fi
+
+# Check whether column parameter exists and is present in attribute table - there must be a better way of doing this.
+
+COLTEST=`db.columns table=$TABLE driver=$DRIVER database=$DATABASE | grep "$COLUMN"`
+
+if [ $? -ne 0 -o -z "$COLTEST" ] ; then
+ echo ""
+ echo "$SCRIPT: Column '$COLUMN' not found in table $TABLE. Exiting."
+ echo ""
+ exit 1
+fi
+
+# Check if we have selected image viewer - insert support for other viewers here as needed
+
+case "$VIEWER" in
+
+eog) if [ ! -x "`which eog`" ] ; then
+ echo ""
+ echo "$SCRIPT: Eye of Gnome viewer required, please install first or select another viewer." 2>&1
+ echo ""
+ exit 1
+ fi
+;;
+
+gimp) if [ ! -x "`which gimp`" ] ; then
+ echo ""
+ echo "$SCRIPT: Gimp required, please install first or select another viewer." 2>&1
+ echo ""
+ exit 1
+ fi
+;;
+
+gpdf) if [ ! -x "`which gpdf`" ] ; then
+ echo ""
+ echo "$SCRIPT: gpdf required, please install first or select another viewer." 2>&1
+ echo ""
+ exit 1
+ fi
+;;
+
+gthumb) if [ ! -x "`which gthumb`" ] ; then
+ echo ""
+ echo "$SCRIPT: gthumb required, please install first or select another viewer." 2>&1
+ echo ""
+ exit 1
+ fi
+;;
+
+inkscape) if [ ! -x "`which inkscape`" ] ; then
+ echo ""
+ echo "$SCRIPT: inkscape required, please install first or select another viewer." 2>&1
+ echo ""
+ exit 1
+ fi
+;;
+
+*) echo ""
+ echo "$SCRIPT: $VIEWER is not one of the supported viewers - please select another." 2>&1
+ echo ""
+ exit 1
+;;
+
+esac
+
+# Now query vector map and load hyperlink into viewer.
+
+if [ "$GIS_FLAG_i" -eq 1 ] ; then
+
+ STATUS=1
+ while [ "$STATUS" -eq 1 ] ; do
+ echo ""
+ echo "Click on a vector point to load hyperlink..."
+ LINK_DOC=`d.what.vect -1t map=$INPUT | grep $COLUMN | awk -F": " '{print $2}'`
+
+ if [ -z "$LINK_DOC" ] ; then
+ echo ""
+ echo "Null statement received for vector hyperlink. Exiting."
+ echo ""
+ exit 1
+ else
+ echo ""
+ echo "Received hyperlink document named '$LINK_DOC'..."
+ echo "The image pathname will be $FOLDER/$LINK_DOC..."
+ echo "Loading image into $VIEWER..."
+ fi
+
+ # Load hyperlink in selected image viewer.
+ $VIEWER $FOLDER/$LINK_DOC
+ echo ""
+ echo "Continue? Type 'q' to quit, or any other key plus RETURN to continue."
+ read CONFIRM
+
+ if [ "$CONFIRM" = "q" -o "$CONFIRM" = "Q" ] ; then
+ echo ""
+ echo "Exiting - Goodbye!"
+ STATUS=0
+ fi
+
+ done
+
+else #Use sql query to select vector
+
+ QUERY="$GIS_OPT_where"
+
+ if [ -z "$QUERY" ] ; then
+ echo ""
+ echo "Please enter an SQL 'where' query (example: cat=36)"
+ echo ""
+ exit 1
+ fi
+
+ LINK_DOC=`echo "select $COLUMN from $TABLE where $QUERY" | db.select -c`
+
+ if [ -z "$LINK_DOC" ] ; then
+ echo ""
+ echo "$SCRIPT: No hyperlink match found in $TABLE for '$QUERY'. Exiting."
+ echo ""
+ exit 1
+ fi
+
+ echo ""
+ echo "Received hyperlink document named '$LINK_DOC'..."
+ echo "The image pathname will be $FOLDER/$LINK_DOC..."
+ echo "Loading image into $VIEWER..."
+
+ # Load hyperlink in selected image viewer.
+ $VIEWER $FOLDER/$LINK_DOC
+fi
+
+
+exit 0
Property changes on: grass-addons/grass6/display/d.hyperlink/d.hyperlink
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:mime-type
+ text/x-sh
Added: svn:eol-style
+ native
Added: grass-addons/grass6/display/d.hyperlink/description.html
===================================================================
--- grass-addons/grass6/display/d.hyperlink/description.html (rev 0)
+++ grass-addons/grass6/display/d.hyperlink/description.html 2012-11-06 14:10:59 UTC (rev 53703)
@@ -0,0 +1,15 @@
+<h2>DESCRIPTION</h2>
+
+<em>d.hyperlink</em> is an interactive shell script that allows the viewing
+of hyperlinked images from a vector's attribute table in an external image
+viewer. Queries can be made via SQL statements or interactive mouse-clicking.
+The attribute table must be pre-populated with a column containing the image
+to link the vector to; the user also specifies the image folder in the
+current MAPSET where the images are located. The script currently supports
+gimp, Eye of Gnome, gthumb, gpdf, and Inkscape image viewers.
+
+<h2>AUTHOR</h2>
+
+Eric Patton, 2006
+
+<p><i>Last changed: $Date$</i>
Property changes on: grass-addons/grass6/display/d.hyperlink/description.html
___________________________________________________________________
Added: svn:mime-type
+ text/html
Added: svn:keywords
+ Author Date Id
Added: svn:eol-style
+ native
More information about the grass-commit
mailing list