[GRASS-SVN] r58879 - grass/branches/develbranch_6/raster/r.li/r.li.setup

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Feb 4 11:19:19 PST 2014


Author: hamish
Date: 2014-02-04 11:19:19 -0800 (Tue, 04 Feb 2014)
New Revision: 58879

Modified:
   grass/branches/develbranch_6/raster/r.li/r.li.setup/masked_area_selection.sh
Log:
script cleanups, more to come for this file

Modified: grass/branches/develbranch_6/raster/r.li/r.li.setup/masked_area_selection.sh
===================================================================
--- grass/branches/develbranch_6/raster/r.li/r.li.setup/masked_area_selection.sh	2014-02-04 15:09:15 UTC (rev 58878)
+++ grass/branches/develbranch_6/raster/r.li/r.li.setup/masked_area_selection.sh	2014-02-04 19:19:19 UTC (rev 58879)
@@ -1,77 +1,89 @@
 #!/bin/sh
-#%Module 
+#
+# Masked area selection using r.digit
+#
+
+#%Module
 #%description: Select a circular or polygonal area
 #%End
 #%option
 #% key: raster
 #% type: string
-#% description: raster map to to analyse
+#% description: Raster map to to analyse
 #% required: yes
 #%end
 #%option
 #% key: vector
 #% type: string
-#% description: vector to overlay
+#% description: Vector map to overlay
 #% required: no
 #%end
 #%option
 #% key: site
 #% type: string
-#% description: site to overlay
+#% description: Vector points map to overlay
 #% required: no
 #%end
 #%option
 #% key: conf
 #% type: string
-#% description: name of configuration file where insert areas
+#% description: Name of configuration file where insert areas
 #% required: yes
 #%end
 #%option
 #% key: north
 #% type: string
-#% description: nothern edge (use only with f flag)
+#% description: Northern edge (use only with the 'f' flag)
 #% required: no
 #%end
 #%option
 #% key: south
 #% type: string
-#% description:south edge (use only with f flag)
+#% description: Southern edge (use only with the 'f' flag)
 #% required: no
 #%end
 #%option
 #% key: east
 #% type: string
-#% description: east edge(use only with f flag)
+#% description: Eastern edge (use only with the 'f' flag)
 #% required: no
 #%end
 #%option
 #% key: west 
 #% type: string
-#% description: west edge(use only with f flag)
+#% description: Western edge (use only with the 'f' flag)
 #% required: no
 #%end
 #%flag
 #% key: f
-#% description: sample frame yet selected 
+#% description: Sample frame not yet selected, set from module options
 #%end
 #%flag
 #% key: c
-#% description: take a circular area
+#% description: Take a circular area
 #%end
 
 # Where to find the others scripts
 f_path="$GISBASE/etc/r.li.setup"
 
-# Check if we have grass
+# Check if we are in a GRASS session
 if test "$GISBASE" = ""; then
- echo "You must be in GRASS GIS to run this program." >&2
- exit 1
+   echo "You must be in GRASS GIS to run this program." 1>&2
+   exit 1
 fi
 
 if [ "$1" != "@ARGS_PARSED@" ] ; then
-  exec g.parser "$0" "$@"
+   exec g.parser "$0" "$@"
 fi
 
+
+#### environment variables
+GISDBASE=`g.gisenv get=GISDBASE`
+LOCATION=`g.gisenv get=LOCATION_NAME`
+MAPSET=`g.gisenv get=MAPSET`
+: ${GISDBASE?} ${LOCATION?} ${MAPSET?}
+
+
 #### set temporary files
 TMP="`g.tempfile pid=$$`"
 if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
@@ -80,46 +92,46 @@
 fi
 
 
-#### environment variables
-g.gisenv LOCATION_NAME > $TMP.var
-read LOCATION < $TMP.var
-g.gisenv GISDBASE > $TMP.var
-read GISDBASE < $TMP.var
-g.gisenv MAPSET > $TMP.var
-read MAPSET < $TMP.var
+# FIXME: use WIND_OVERRIDE
+
 # show the sampling frame
-
-if [ $GIS_FLAG_f -eq 1 ] ; then
-    g.region n=$GIS_OPT_north s=$GIS_OPT_south e=$GIS_OPT_east w=$GIS_OPT_west
+if [ "$GIS_FLAG_f" -eq 1 ] ; then
+    g.region n="$GIS_OPT_north" s="$GIS_OPT_south" e="$GIS_OPT_east" w="$GIS_OPT_west"
 else
-    g.region rast=$GIS_OPT_raster
+    g.region rast="$GIS_OPT_raster"
 fi
-# open x1 monitor
+
+# open x1 Xmonitor
 d.mon stop=x1
 d.mon start=x1
 
-d.rast -o map=$GIS_OPT_raster
+d.rast -o map="$GIS_OPT_raster"
+
 if [ -n "$GIS_OPT_vector" ] ; then
-    d.vect map=$GIS_OPT_vector
+    d.vect map="$GIS_OPT_vector"
 fi
 if [ -n "$GIS_OPT_site" ] ; then 
-    d.vect  map=$GIS_OPT_site
+    d.vect map="$GIS_OPT_site"
 fi
-#let draw area
-if [ $GIS_FLAG_c -eq 1 ] ; then
-    cp $f_path/circle.txt $$.txt 
-    echo "$$" >> $$.txt 
+
+# setup for drawing area
+if [ "$GIS_FLAG_c" -eq 1 ] ; then
+   RDIG_INSTR="$f_path/circle.txt"
 else
-    cp $f_path/polygon.txt  $$.txt 
-    echo "$$" >> $$.txt
+   RDIG_INSTR="$f_path/polygon.txt"
 fi
- 
-r.digit < $$.txt
 
-#show the selected area
-d.rast -o map=$$ 
-export name=$$.val
-$GRASS_WISH $f_path/area_query 
+# feed options to r.digit
+r.digit output="tmp_rli_mask.$$" < "$RDIG_INSTR"
+
+
+# show the selected area
+d.rast -o map="tmp_rli_mask.$$"
+
+name=$$.val
+export name
+
+"$GRASS_WISH" "$f_path/area_query"
     cat $name | cut -f1 -d ' ' > $name.var
     read ok < $name.var
     cat $name | cut -f2 -d' ' > $name.var
@@ -163,6 +175,9 @@
     fi
 
 d.mon stop=x1
-#clean tmp files
-rm -f $$*
-rm -f $TMP*
+
+# clean tmp files
+#FIXME: use g.tempfile
+rm -f "$$"*
+rm -f "$TMP"*
+



More information about the grass-commit mailing list