[GRASS-SVN] r58964 - grass/trunk/raster/r.li/r.li.setup
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Feb 8 22:05:24 PST 2014
Author: hamish
Date: 2014-02-08 22:05:24 -0800 (Sat, 08 Feb 2014)
New Revision: 58964
Modified:
grass/trunk/raster/r.li/r.li.setup/masked_area_selection.sh
grass/trunk/raster/r.li/r.li.setup/sample_area_vector.sh
grass/trunk/raster/r.li/r.li.setup/square_mouse_selection.sh
Log:
sync old r.li.setup scripts with devbr6 (up to r58914)
Modified: grass/trunk/raster/r.li/r.li.setup/masked_area_selection.sh
===================================================================
--- grass/trunk/raster/r.li/r.li.setup/masked_area_selection.sh 2014-02-09 05:57:12 UTC (rev 58963)
+++ grass/trunk/raster/r.li/r.li.setup/masked_area_selection.sh 2014-02-09 06:05:24 UTC (rev 58964)
@@ -9,25 +9,33 @@
#%option
#% key: raster
#% type: string
+#% gisprompt: old,cell,raster
+#% key_desc: name
#% description: Raster map to to analyse
#% required: yes
#%end
#%option
#% key: vector
#% type: string
+#% gisprompt: old,vector,vector
+#% key_desc: name
#% description: Vector map to overlay
#% required: no
#%end
#%option
#% key: site
#% type: string
+#% gisprompt: old,vector,vector
+#% key_desc: name
#% description: Vector points map to overlay
#% required: no
#%end
#%option
#% key: config
#% type: string
-#% description: Name of configuration file where insert areas
+#% gisprompt: new_file,file,output
+#% key_desc: filename
+#% description: Name of configuration file where areas are to be saved
#% required: yes
#%end
#%option
@@ -90,27 +98,53 @@
exit 1
fi
+cleanup()
+{
+ # remove temporary region
+ eval `g.findfile elem=windows file="tmp_rli_selmsk.$$" | grep '^name='`
+ if [ -n "$name" ] ; then
+ g.region region="tmp_rli_selmsk.$$"
+ g.remove region="tmp_rli_selmsk.$$" --quiet
+ fi
-# FIXME: use WIND_OVERRIDE
+ rm -f "$TMP" "$TMP".val
+}
+trap "cleanup" 2 3 15
-# show the sampling frame
+
+# setup internal region
+# (WIND_OVERRIDE is already present by the main r.li.setup script)
+g.region save="tmp_rli_selmsk.$$"
+
+# ?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"
+ 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"
fi
-# open x1 Xmonitor
-d.mon stop=x1
-d.mon start=x1
+# find a free Xmonitor
+XMON=x1
+for i in 1 2 3 4 5 6 7 ; do
+ result=`d.mon -L | grep -w "^x$i"`
+ if [ `echo "$result" | grep -c 'not'` -eq 1 ] ; then
+ XMON="x$i"
+ break
+ fi
+done
+# open the Xmonitor
+d.mon stop="$XMON"
+d.mon start="$XMON"
+
d.rast -o map="$GIS_OPT_raster"
if [ -n "$GIS_OPT_vector" ] ; then
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" color=red fcolor=red size=5 icon=basic/circle
fi
# setup for drawing area
@@ -127,56 +161,49 @@
# show the selected area
d.rast -o map="tmp_rli_mask.$$"
-name=$$.val
+name="$TMP.val"
export name
+# ask if it's ok, save 0,1 to "$name" temp file
"$GRASS_WISH" "$f_path/area_query"
- cat $name | cut -f1 -d ' ' > $name.var
- read ok < $name.var
- cat $name | cut -f2 -d' ' > $name.var
- r_name=""
- read r_name < $name.var
- if [ $ok -eq 1 ] ; then
- r.to.vect input="$$" output="v$$" feature=area
- g.region vect="v$$"
- v.to.rast input="v$$" output=$r_name value=1 use=val
- #write info in configuration file
- g.region -g| grep "n=" | cut -f2 -d'='> $name.var
- read north < $name.var
- g.region -g| grep "s=" | cut -f2 -d'=' > $name.var
- read south < $name.var
- g.region -g| grep "e=" | cut -f2 -d'=' > $name.var
- read east < $name.var
- g.region -g| grep "w=" | cut -f2 -d'=' > $name.var
- read west < $name.var
- echo "SAMPLEAREAMASKED $r_name $north|$south|$east|$west" >>\
- $GIS_OPT_conf
- #remove tmp raster and vector
- g.remove rast=$$
- g.remove vect=v$$
- #rm -f "$GISDBASE"/"$LOCATION"/"$MAPSET"/cats/"$$"
- #rm -f "$GISDBASE"/"$LOCATION"/"$MAPSET"/cell/"$$"
- #rm -f "$GISDBASE"/"$LOCATION"/"$MAPSET"/cellhd/"$$"
- #rm -fR "$GISDBASE"/"$LOCATION"/"$MAPSET"/cell_misc/"$$"
- #rm -f "$GISDBASE"/"$LOCATION"/"$MAPSET"/colr/"$$"
- #rm -f "$GISDBASE"/"$LOCATION"/"$MAPSET"/hist/"$$"
- #rm -fR "$GISDBASE"/"$LOCATION"/"$MAPSET"/vector/"v$$"
- echo DROP TABLE "v$$" | db.execute
-
- 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
- fi
+ok=`cat "$name" | cut -f1 -d ' '`
+r_name=`cat "$name" | cut -f2 -d' '`
+
+
+if [ "$ok" -eq 1 ] ; then
+ # r.mask + 'g.region zoom= align=' + 'r.mapcalc cropmap=map' would be cleaner?
+ r.to.vect input="tmp_rli_mask.$$" output="tmp_rli_mask_v$$" feature=area
+ g.region vect="tmp_rli_mask_v$$"
+ v.to.rast input="tmp_rli_mask_v$$" output="$r_name" value=1 use=val
+
+ # write info in configuration file
+ eval `g.region -g`
+ north="$n"
+ south="$s"
+ east="$e"
+ west="$w"
+
+ echo "SAMPLEAREAMASKED $r_name $north|$south|$east|$west" >> \
+ "$GIS_OPT_conf"
+
+ # remove tmp raster and vector
+ g.remove rast="tmp_rli_mask.$$" --quiet
+ g.remove vect="tmp_rli_mask_v$$" --quiet
+
+ 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
- echo 0 >> $GIS_OPT_conf
+ g.region rast="$GIS_OPT_raster"
fi
-d.mon stop=x1
+else
+ echo 0 >> "$GIS_OPT_conf"
+fi
+
+d.mon stop="$XMON"
+
# clean tmp files
-#FIXME: use g.tempfile
-rm -f "$$"*
-rm -f "$TMP"*
-
+cleanup
Modified: grass/trunk/raster/r.li/r.li.setup/sample_area_vector.sh
===================================================================
--- grass/trunk/raster/r.li/r.li.setup/sample_area_vector.sh 2014-02-09 05:57:12 UTC (rev 58963)
+++ grass/trunk/raster/r.li/r.li.setup/sample_area_vector.sh 2014-02-09 06:05:24 UTC (rev 58964)
@@ -1,4 +1,4 @@
-#!/bin/sh -x
+#!/bin/sh
#
# This program is free software under the GPL (>=v2)
# Read the COPYING file that comes with GRASS for details.
@@ -24,7 +24,7 @@
#% required: yes
#%end
#%option
-#% key: config
+#% key: conf
#% type: string
#% key_desc: name
#% gisprompt: new_file,file,output
@@ -43,12 +43,6 @@
exec g.parser "$0" "$@"
fi
-#### set temporary files
-TMP="`g.tempfile pid=$$`"
-if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
- echo "ERROR: unable to create temporary files" 1>&2
- exit 1
-fi
#### environment variables
GISDBASE=`g.gisenv get=GISDBASE`
@@ -56,29 +50,34 @@
MAPSET=`g.gisenv get=MAPSET`
: ${GISDBASE?} ${LOCATION?} ${MAPSET?}
-f_path="$GISBASE/etc/r.li.setup"
-##############################################################
-# read categories from input vector, extract,
-# convert to raster and save the bounds to configuration file
-##############################################################
+#### set temporary files
+TMP="`g.tempfile pid=$$`"
+if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
+ echo "ERROR: unable to create temporary files" 1>&2
+ exit 1
+fi
-# using v.category instead of v.build with cdump
-v.category input=$GIS_OPT_vector option=print | sort | uniq > "$TMP.cat"
-# get input vector name
-GIS_OPT_input_vector=`echo $GIS_OPT_vector| cut -d'@' -f 1`
+cleanup()
+{
+ # remove temporary region
+ eval `g.findfile elem=windows file="tmp_rli_sampvect.$$" | grep '^name='`
+ if [ -n "$name" ] ; then
+ g.region region="tmp_rli_sampvect.$$"
+ g.remove region="tmp_rli_sampvect.$$" --quiet
+ fi
-# get input vector mapset
-GIS_OPT_input_mapset=`echo $GIS_OPT_vector| cut -d'@' -f 2`
+ rm -f "$TMP"*
+}
+trap "cleanup" 2 3 15
-# read input vector categories into CAT_LIST array
-IFS=$'\r\n' CAT_LIST=($(cat $TMP.cat))
-# save the current region settings temporarily to avoid surpirses later.
-TMP_REGION="tmp_rlisetup.sampvect.$$"
-g.region save="$TMP_REGION"
+# setup internal region
+# (WIND_OVERRIDE is already present by the main r.li.setup script)
+g.region save="tmp_rli_sampvect.$$"
+
# find a free Xmonitor
XMON=x1
for i in 1 2 3 4 5 6 7 ; do
@@ -89,48 +88,66 @@
fi
done
+# open Xmonitor
+d.mon stop="$XMON"
+d.mon start="$XMON"
-# process each feature in the vector having category values in the CAT_LIST array
-for CAT in "${CAT_LIST[@]}"
-do
- # vector to store a feature fro $GIS_OPT_vector with category value $CAT.
- # This temporary vector will be removed at the end.
- EXTRACT=$GIS_OPT_input_vector"_"$CAT"_part@"$GIS_OPT_input_mapset
- # extract only a part of $GIS_OPT_vector where category = $CAT and store in $EXTRACT
- v.extract input=$GIS_OPT_vector output=$EXTRACT \
- type=point,line,boundary,centroid,area,face \
- new=-1 -d where='CAT='$CAT
+f_path="$GISBASE/etc/r.li.setup"
- # open Xmonitor
- d.mon stop="$XMON"
- d.mon start="$XMON"
+##############################################################
+# read categories from input vector, extract,
+# convert to raster and save the bounds to configuration file
+##############################################################
+# using v.category instead of v.build with cdump
+v.category input="$GIS_OPT_vector" option=print | \
+ sort -n | uniq > "$TMP.cat"
+
+# crop away @mapset part, if present
+input_vector=`echo "$GIS_OPT_vector" | cut -d'@' -f 1`
+
+
+# process each feature in the vector that has a cat
+while read CAT ; do
+ # skip blank lines..
+ if [ -z "$CAT" ] ; then
+ continue
+ fi
+
+ # Temporary vector map to store an individual feature from the input vector
+ # It will be removed at the end of the iteration.
+ EXTRACT="tmp_$$_${input_vector}_${CAT}"
+
+ v.extract input="$GIS_OPT_vector" output="$EXTRACT" \
+ type=point,line,centroid,area \
+ new=-1 -d list="$CAT" # where="CAT = $CAT"
+
# set region with raster resolution
g.region vect="$EXTRACT" align="$GIS_OPT_raster"
+
+ d.erase
d.rast -o "$GIS_OPT_raster"
- # render extracted vector map
+ # render extracted vector map (prehaps fcolor=none for areas?)
d.vect "$EXTRACT"
# ask the user to analyse this vector and a name for raster in a Tcl GUI
name="$TMP.val" # where find the answer
export name
+ # ask if it's ok, save 0,1 to "$name" temp file
"$GRASS_WISH" "$f_path/area_query"
ok=`cat "$name" | cut -f1 -d ' '`
- #cat "$name" | cut -f1 -d ' ' > "$name.var"
- #read ok < "$name.var"
r_name=`cat "$name" | cut -f2 -d' '`
- #cat "$name" | cut -f2 -d' ' > "$name.var"
- #r_name=""
- #read r_name < "$name.var"
+
+ # debug or needed?
echo "$r_name"
if [ "$ok" -eq 1 ] ; then
#area selected, create mask
- v.to.rast input="$EXTRACT" output="$r_name" use=cat value=1 rows=4096
+ v.to.rast input="$EXTRACT" output="$r_name" use=cat
# save the region settings into the configuration file
eval `g.region -g`
@@ -138,17 +155,13 @@
fi
#remove temporary vector map created from v.extract
- g.remove vect="$EXTRACT"
- #rm -fR "$GISDBASE"/"$LOCATION"/"$MAPSET"/vector/$GIS_OPT_vector"part"$I
- #echo DROP TABLE $GIS_OPT_vector"part"$I | db.execute
-done
+ g.remove vect="$EXTRACT" --quiet
+done < "$TMP.cat"
+
+
d.mon stop="$XMON"
-# restore the region (which itself is a WIND_OVERRIDE temporary region by
-# the r.li.setup main script)
-g.region region="$TMP_REGION"
-g.remove region="$TMP_REGION"
-# clean tmp files
-rm -f "$TMP"*
+# clean tmp files and restore region
+cleanup
Modified: grass/trunk/raster/r.li/r.li.setup/square_mouse_selection.sh
===================================================================
--- grass/trunk/raster/r.li/r.li.setup/square_mouse_selection.sh 2014-02-09 05:57:12 UTC (rev 58963)
+++ grass/trunk/raster/r.li/r.li.setup/square_mouse_selection.sh 2014-02-09 06:05:24 UTC (rev 58964)
@@ -69,7 +69,7 @@
# Check if we are in a GRASS session
if test "$GISBASE" = ""; then
- echo "You must be in GRASS GIS to run this program." >&2
+ echo "You must be in GRASS GIS to run this program." 1>&2
exit 1
fi
@@ -77,14 +77,6 @@
exec g.parser "$0" "$@"
fi
-
-# open x1 Xmonitor
-d.mon stop=x1
-d.mon start=x1
-
-
-g.region rast=$GIS_OPT_raster
-
#### create temporary file
TMP="`g.tempfile pid=$$`"
if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
@@ -92,21 +84,51 @@
exit 1
fi
-#saving starting values
-g.region -g | grep "n=" | cut -f2 -d'=' > $TMP.var
-read s_n < $TMP.var
-g.region -g | grep "s=" | cut -f2 -d'=' > $TMP.var
-read s_s < $TMP.var
-g.region -g | grep "e=" | cut -f2 -d'=' > $TMP.var
-read s_e < $TMP.var
-g.region -g | grep "w=" | cut -f2 -d'=' > $TMP.var
-read s_w < $TMP.var
-g.region -g | grep "nsres=" | cut -f2 -d'=' > $TMP.var
-read s_nsres < $TMP.var
-g.region -g | grep "ewres=" | cut -f2 -d'=' > $TMP.var
-read s_ewres < $TMP.var
-echo "START $s_n|$s_s|$s_e|$s_w|$s_nsres|$s_ewres" >> $GIS_OPT_conf
+cleanup()
+{
+ # remove temporary region
+ eval `g.findfile elem=windows file="tmp_rli_sq.$$" | grep '^name='`
+ if [ -n "$name" ] ; then
+ g.region region="tmp_rli_sq.$$"
+ g.remove region="tmp_rli_sq.$$" --quiet
+ fi
+ rm -f "$TMP" "$TMP.var"
+}
+trap "cleanup" 2 3 15
+
+
+# find a free Xmonitor
+XMON=x1
+for i in 1 2 3 4 5 6 7 ; do
+ result=`d.mon -L | grep -w "^x$i"`
+ if [ `echo "$result" | grep -c 'not'` -eq 1 ] ; then
+ XMON="x$i"
+ break
+ fi
+done
+
+# open the Xmonitor
+d.mon stop="$XMON"
+d.mon start="$XMON"
+
+
+# setup internal region
+# (WIND_OVERRIDE is already present by the main r.li.setup script)
+g.region save="tmp_rli_sq.$$"
+g.region rast="$GIS_OPT_raster"
+
+# store starting values
+eval `g.region -g`
+s_n="$n"
+s_s="$s"
+s_e="$e"
+s_w="$w"
+s_nsres="$nsres"
+s_ewres="$ewres"
+
+echo "START $s_n|$s_s|$s_e|$s_w|$s_nsres|$s_ewres" >> "$GIS_OPT_conf"
+
# show the sampling frame
if [ "$GIS_FLAG_f" -eq 1 ] ; then
g.region n="$GIS_OPT_north" s="$GIS_OPT_south" \
@@ -122,41 +144,42 @@
d.vect map="$GIS_OPT_site" color=red fcolor=red size=5 icon=basic/circle
fi
-# let draw area
+# have the user selected the area of interest with the mouse
+
+# TODO: popup message? (d.menu: "Draw box now: [ok]")
+######
+#d.menu bcolor=aqua tcolor=black << EOF
+#.T 20
+#.L 20
+#Next select area with mouse
+# [ Ok ]
+#EOF
+######
+
d.zoom
+
# ask if the selected area is right
-name="$TMP" # file where write the answer
+name="$TMP.var" # temp file where the answer is written to by the tcl pop-up
export name
+# ask if it's ok, save 0,1 to the "$name" tmp file
"$GRASS_WISH" "$f_path/square_query"
read ok < "$TMP.var"
if [ "$ok" -eq 0 ] ; then
echo "NO" >> "$GIS_OPT_conf"
+elif [ "$ok" -eq 1 ] ; then
+ # write the square boundaries
+ eval `g.region -g`
+ echo "SQUAREAREA $n|$s|$e|$w|$nsres|$ewres" >> "$GIS_OPT_conf"
+else
+ g.message -e "Unable to ascertain if the selected area was ok or not"
fi
-if [ $ok -eq 1 ] ; then
- #write the square boundaries
- g.region -g | grep "n=" | cut -f2 -d'=' > $TMP.var
- read n < $TMP.var
- g.region -g | grep "s=" | cut -f2 -d'=' > $TMP.var
- read s < $TMP.var
- g.region -g | grep "e=" | cut -f2 -d'=' > $TMP.var
- read e < $TMP.var
- g.region -g | grep "w=" | cut -f2 -d'=' > $TMP.var
- read w < $TMP.var
- g.region -g | grep "nsres=" | cut -f2 -d'=' > $TMP.var
- read nsres < $TMP.var
- g.region -g | grep "ewres=" | cut -f2 -d'=' > $TMP.var
- read ewres < $TMP.var
- echo "SQUAREAREA $n|$s|$e|$w|$nsres|$ewres" >> $GIS_OPT_conf
-fi
-
# close the Xmonitor
-d.mon stop=x1
+d.mon stop="$XMON"
-# clean tmp files
-rm -f $TMP*
-
+# clean tmp files and temporary region
+cleanup
More information about the grass-commit
mailing list