[GRASS-SVN] r45611 - in grass/branches/develbranch_6/scripts:
db.out.ogr r.fillnulls r.mask r.reclass.area v.dissolve
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Mar 9 01:42:07 EST 2011
Author: hamish
Date: 2011-03-08 22:42:07 -0800 (Tue, 08 Mar 2011)
New Revision: 45611
Modified:
grass/branches/develbranch_6/scripts/db.out.ogr/db.out.ogr
grass/branches/develbranch_6/scripts/r.fillnulls/r.fillnulls
grass/branches/develbranch_6/scripts/r.mask/r.mask
grass/branches/develbranch_6/scripts/r.reclass.area/r.reclass.area
grass/branches/develbranch_6/scripts/v.dissolve/v.dissolve
Log:
quote variables
Modified: grass/branches/develbranch_6/scripts/db.out.ogr/db.out.ogr
===================================================================
--- grass/branches/develbranch_6/scripts/db.out.ogr/db.out.ogr 2011-03-09 06:01:52 UTC (rev 45610)
+++ grass/branches/develbranch_6/scripts/db.out.ogr/db.out.ogr 2011-03-09 06:42:07 UTC (rev 45611)
@@ -99,7 +99,7 @@
fi
fi
-v.out.ogr --q $GIS_OPT_INPUT dsn="$GIS_OPT_DSN" $OLAYER format=$GIS_OPT_FORMAT type=point
+v.out.ogr --q "$GIS_OPT_INPUT" dsn="$GIS_OPT_DSN" "$OLAYER" format="$GIS_OPT_FORMAT" type=point
if [ $? -ne 0 ] ; then
exit 1
fi
Modified: grass/branches/develbranch_6/scripts/r.fillnulls/r.fillnulls
===================================================================
--- grass/branches/develbranch_6/scripts/r.fillnulls/r.fillnulls 2011-03-09 06:01:52 UTC (rev 45610)
+++ grass/branches/develbranch_6/scripts/r.fillnulls/r.fillnulls 2011-03-09 06:42:07 UTC (rev 45611)
@@ -82,36 +82,34 @@
eval `g.gisenv`
: ${GISBASE?} ${GISDBASE?} ${LOCATION_NAME?} ${MAPSET?}
-LOCATION=$GISDBASE/$LOCATION_NAME/$MAPSET
+LOCATION="$GISDBASE/$LOCATION_NAME/$MAPSET"
# what to do in case of user break:
exitprocedure()
{
- g.message -e 'User break!'
- #delete internal mask and any TMP files:
- g.remove rast=$TMP1,$TMP1.buf,${TMP1}_filled > /dev/null
- g.remove vect=${VECTTMP} > /dev/null
-
- #restore user mask if present:
- if test -f $LOCATION/cell/$USERMASK ; then
- g.remove rast=MASK > /dev/null
- g.rename $USERMASK,MASK > /dev/null
- fi
- exit 1
+ g.message -e 'User break!'
+ #delete internal mask and any TMP files:
+ g.remove rast="$TMP1","$TMP1.buf","${TMP1}_filled" --quiet > /dev/null
+ g.remove vect="$VECTTMP" --quiet > /dev/null
+
+ #restore user mask if present:
+ if test -f $LOCATION/cell/$USERMASK ; then
+ g.remove rast=MASK --quiet > /dev/null
+ g.rename "$USERMASK",MASK --quiet > /dev/null
+ fi
+ exit 1
}
# shell check for user break (signal list: trap -l)
trap "exitprocedure" 2 3 15
#test:
-if [ ! $GIS_OPT_INPUT ]
-then
- g.message "Please provide an input map name."
- exit 1
+if [ -z "$GIS_OPT_INPUT" ] ; then
+ g.message "Please provide an input map name."
+ exit 1
fi
-if [ ! $GIS_OPT_OUTPUT ]
-then
- g.message "Please provide an output name."
- exit 1
+if [ -z "$GIS_OPT_OUTPUT" ] ; then
+ g.message "Please provide an output name."
+ exit 1
fi
#check if input file exists
@@ -123,11 +121,11 @@
#check if a MASK is already present:
MASKTMP=mask.$$
-USERMASK=usermask_${MASKTMP}
-if test -f $LOCATION/cell/MASK
+USERMASK="usermask_$MASKTMP"
+if test -f "$LOCATION/cell/MASK"
then
g.message "A user raster mask (MASK) is present. Saving it..."
- g.rename MASK,$USERMASK > /dev/null
+ g.rename MASK,"$USERMASK" --quiet > /dev/null
fi
#make a mask of NULL cells
@@ -139,7 +137,7 @@
g.message "Locating and isolating NULL areas..."
#creating 0/1 map:
-r.mapcalc $TMP1="if(isnull($GIS_OPT_INPUT),1,null())"
+r.mapcalc "$TMP1 = if(isnull($GIS_OPT_INPUT),1,null())"
#generate a ring:
# the buffer is set to three times the map resolution so you get nominally
@@ -149,52 +147,54 @@
# around the edges when distance > mean (.5 of the time? diagonals? worse
# when ewres!=nsres).
eval `g.region -gm | grep res`
+# check-me: quoting ok?
RES="`echo $nsres $ewres | awk '{printf "%f", ($1+$2) * 3. / 2.}'`" # avg*3
-r.buffer input=$TMP1 dist=$RES out=$TMP1.buf
+r.buffer input="$TMP1" dist="$RES" out="$TMP1.buf"
if [ $? -ne 0 ] ; then
g.message -e "$0 abandoned. Removing temporary map, restoring user mask if needed:"
- g.remove rast=MASK,$TMP1,$TMP1.buf,${TMP1}_filled > /dev/null
- g.remove vect=${VECTTMP} > /dev/null
- g.rename $USERMASK,MASK > /dev/null
+ g.remove rast=MASK,"$TMP1","$TMP1.buf","${TMP1}_filled" --quiet > /dev/null
+ g.remove vect="$VECTTMP" --quiet > /dev/null
+ g.rename "$USERMASK",MASK --quiet > /dev/null
exit 1
fi
-r.mapcalc "MASK=if($TMP1.buf==2,1,null())"
+r.mapcalc "MASK = if($TMP1.buf==2,1,null())"
# now we only see the outlines of the NULL areas if looking at INPUT.
# Use this outline (raster border) for interpolating the fill data:
VECTTMP=vecttmp_fillnulls_$$
g.message "Creating interpolation points..."
-r.to.vect input=$GIS_OPT_INPUT output=${VECTTMP} feature=point
+r.to.vect input="$GIS_OPT_INPUT" output="$VECTTMP" feature=point
if [ $? -ne 0 ] ; then
g.message -e "$0 abandoned. Removing temporary maps, restoring user mask if needed:"
- g.remove rast=MASK,$TMP1,$TMP1.buf,${TMP1}_filled > /dev/null
- g.remove vect=${VECTTMP} > /dev/null
- g.rename $USERMASK,MASK > /dev/null
+ g.remove rast=MASK,"$TMP1","$TMP1.buf","${TMP1}_filled" --quiet > /dev/null
+ g.remove vect="$VECTTMP" --quiet > /dev/null
+ g.rename "$USERMASK",MASK --quiet > /dev/null
exit 1
fi
#count number of points to control segmax parameter for interpolation:
-POINTSNUMBER="`v.info -t map=${VECTTMP} | grep points | cut -d'=' -f2`"
+# check-me: quoting?
+POINTSNUMBER="`v.info -t map="$VECTTMP" | grep points | cut -d'=' -f2`"
g.message "Interpolating $POINTSNUMBER points"
-if [ $POINTSNUMBER -lt 2 ] ; then
+if [ "$POINTSNUMBER" -lt 2 ] ; then
g.message -w "Not sufficient points to interpolate. Maybe no hole(s) to fill in the current map region?"
#remove internal MASK first
g.remove MASK > /dev/null
#restoring user's mask, if present:
- if test -f $LOCATION/cell/$USERMASK
+ if test -f "$LOCATION/cell/$USERMASK"
then
g.message "Restoring user mask (MASK)..."
- g.rename $USERMASK,MASK > /dev/null
+ g.rename "$USERMASK",MASK --quiet > /dev/null
fi
#cleanup
- g.remove rast=$TMP1,$TMP1.buf,${TMP1}_filled > /dev/null
- g.remove vect=${VECTTMP} > /dev/null
+ g.remove rast="$TMP1","$TMP1.buf","${TMP1}_filled" --quiet > /dev/null
+ g.remove vect="$VECTTMP" --quiet > /dev/null
exit 1
fi
@@ -203,7 +203,7 @@
#remove internal MASK first -- WHY???? MN 10/2005
g.remove MASK > /dev/null
-if test -f $LOCATION/cell/$USERMASK
+if test -f "$LOCATION/cell/$USERMASK"
then
g.message "Using user mask while interpolating"
RST_CMD="v.surf.rst zcol=value tension=$GIS_OPT_TENSION smooth=$GIS_OPT_SMOOTH maskmap=$USERMASK"
@@ -212,36 +212,36 @@
fi
SEGMAX=600
-if [ $POINTSNUMBER -ge $SEGMAX ] ; then
+if [ "$POINTSNUMBER" -ge "$SEGMAX" ] ; then
g.message "Using segmentation for interpolation..."
- $RST_CMD input=${VECTTMP} elev=${TMP1}_filled #2> /dev/null
+ $RST_CMD input="$VECTTMP" elev="${TMP1}_filled" #2> /dev/null
else
#if less than $SEGMAX points, use no segmentation for speedup:
g.message "Using no segmentation for interpolation as not needed..."
- $RST_CMD input=${VECTTMP} elev=${TMP1}_filled segmax=$SEGMAX #2> /dev/null
+ $RST_CMD input="$VECTTMP" elev="${TMP1}_filled" segmax="$SEGMAX" #2> /dev/null
fi
g.message "Note: Above warnings may be ignored."
#restoring user's mask, if present:
-if test -f $LOCATION/cell/$USERMASK
+if test -f "$LOCATION/cell/$USERMASK"
then
- g.message "Restoring user mask (MASK)..."
- g.rename $USERMASK,MASK > /dev/null
+ g.message "Restoring user mask (MASK)..."
+ g.rename "$USERMASK",MASK --quiet > /dev/null
fi
#patch orig and fill map
g.message "Patching fill data into NULL areas..."
# we can use --o here as g.parser already checks on startup
-r.patch in=$GIS_OPT_INPUT,${TMP1}_filled out=$GIS_OPT_OUTPUT --o
+r.patch in="$GIS_OPT_INPUT","${TMP1}_filled" out="$GIS_OPT_OUTPUT" --o
#cleanup
-g.remove rast=$TMP1,$TMP1.buf,${TMP1}_filled > /dev/null
-g.remove vect=${VECTTMP} > /dev/null
+g.remove rast="$TMP1","$TMP1.buf","${TMP1}_filled" --quiet > /dev/null
+g.remove vect="$VECTTMP" --quiet > /dev/null
g.message "Filled raster map is: $GIS_OPT_OUTPUT"
# write cmd history:
-r.support $GIS_OPT_OUTPUT history="${CMDLINE}"
+r.support "$GIS_OPT_OUTPUT" history="${CMDLINE}"
g.message "Done."
Modified: grass/branches/develbranch_6/scripts/r.mask/r.mask
===================================================================
--- grass/branches/develbranch_6/scripts/r.mask/r.mask 2011-03-09 06:01:52 UTC (rev 45610)
+++ grass/branches/develbranch_6/scripts/r.mask/r.mask 2011-03-09 06:42:07 UTC (rev 45611)
@@ -58,7 +58,7 @@
fi
if [ -z "$GRASS_VERBOSE" ] || [ "$GRASS_VERBOSE" -le 2 ] ; then
- BEQUIET="--q"
+ BEQUIET="--quiet"
else
BEQUIET=""
fi
@@ -68,7 +68,7 @@
cleanup()
{
- g.remove --q rast=$TEMPRAST
+ g.remove --q rast="$TEMPRAST"
}
# what to do in case of user break:
@@ -83,10 +83,10 @@
trap "exitprocedure" 2 3 15
# if map is given check if existing
-if [ $GIS_OPT_INPUT ]; then
- eval `g.findfile element=cell file=$GIS_OPT_INPUT`
- filename="${fullname}"
- if [ "$filename" = "" ] ; then
+if [ -n "$GIS_OPT_INPUT" ]; then
+ eval `g.findfile element=cell file="$GIS_OPT_INPUT"`
+ filename="$fullname"
+ if [ -z "$filename" ] ; then
g.message -e "Raster map <$GIS_OPT_INPUT> not found"
exit 1
fi
@@ -96,39 +96,39 @@
if [ "$GIS_FLAG_R" -eq 1 ]; then
if test -f "`g.gisenv GISDBASE`/`g.gisenv LOCATION_NAME`/`g.gisenv MAPSET`/cell/MASK" ; then
g.remove rast=MASK
- g.message ${BEQUIET} "Raster MASK removed"
+ g.message $BEQUIET "Raster MASK removed"
else
- g.message ${BEQUIET} -w "No existing MASK to remove"
+ g.message $BEQUIET -w "No existing MASK to remove"
fi
else
if [ ! $GIS_OPT_INPUT ]; then
- g.message ${BEQUIET} -w "No raster map for MASK provided"
+ g.message $BEQUIET -w "No raster map for MASK provided"
exit 1;
fi
if [ "$GIS_FLAG_O" -eq 1 ]; then
- echo "$GIS_OPT_MASKCATS = 1" | r.reclass input=$GIS_OPT_INPUT output=MASK --o
+ echo "$GIS_OPT_MASKCATS = 1" | r.reclass input="$GIS_OPT_INPUT" output=MASK --o
else
# does map exist in CURRENT mapset?
- eval `g.findfile element=cell file=MASK mapset=$MAPSET`
- if [ "$file" ] ; then
+ eval `g.findfile element=cell file=MASK mapset="$MAPSET"`
+ if [ -n "$file" ] ; then
g.message -e "MASK already found in current mapset. Delete first or overwrite"
exit 1
fi
- echo "$GIS_OPT_MASKCATS = 1" | r.reclass input=$GIS_OPT_INPUT output=MASK
+ echo "$GIS_OPT_MASKCATS = 1" | r.reclass input="$GIS_OPT_INPUT" output=MASK
fi
if [ "$GIS_FLAG_I" -eq 1 ]; then
- g.rename --q rast=MASK,$TEMPRAST
- r.mapcalc "MASK=if(isnull($TEMPRAST),1,null())"
- g.remove --q rast=$TEMPRAST
- g.message ${BEQUIET} "Inverted MASK created. All subsequent raster operations"
+ g.rename --q rast=MASK,"$TEMPRAST"
+ r.mapcalc "MASK = if(isnull($TEMPRAST),1,null())"
+ g.remove --q rast="$TEMPRAST"
+ g.message $BEQUIET "Inverted MASK created. All subsequent raster operations"
else
- g.message ${BEQUIET} "MASK created. All subsequent raster operations"
+ g.message $BEQUIET "MASK created. All subsequent raster operations"
fi
- g.message ${BEQUIET} "will be limited to MASK area"
- g.message ${BEQUIET} "Removing or renaming raster file named MASK will"
- g.message ${BEQUIET} "restore raster operations to normal"
+ g.message $BEQUIET "will be limited to MASK area"
+ g.message $BEQUIET "Removing or renaming raster file named MASK will"
+ g.message $BEQUIET "restore raster operations to normal"
fi
exit 0
Modified: grass/branches/develbranch_6/scripts/r.reclass.area/r.reclass.area
===================================================================
--- grass/branches/develbranch_6/scripts/r.reclass.area/r.reclass.area 2011-03-09 06:01:52 UTC (rev 45610)
+++ grass/branches/develbranch_6/scripts/r.reclass.area/r.reclass.area 2011-03-09 06:42:07 UTC (rev 45611)
@@ -74,7 +74,7 @@
LC_NUMERIC=C
export LC_NUMERIC
-infile=`echo $GIS_OPT_INPUT | cut -f1 -d'@'`
+infile=`echo "$GIS_OPT_INPUT" | cut -f1 -d'@'`
outfile="$GIS_OPT_OUTPUT"
g.region -p | head -n 1 |grep 0 > /dev/null
@@ -86,11 +86,11 @@
if [ -n "$GIS_OPT_LESSER" ] ; then
op=0
- limit=$GIS_OPT_LESSER
+ limit="$GIS_OPT_LESSER"
fi
if [ -n "$GIS_OPT_GREATER" ] ; then
op=1
- limit=$GIS_OPT_GREATER
+ limit="$GIS_OPT_GREATER"
fi
if [ -z "$GIS_OPT_GREATER" -a -z "$GIS_OPT_LESSER" ] ; then
g.message -e "You have to specify either lesser= or greater="
@@ -99,19 +99,19 @@
file2="$infile.clump.$outfile"
-eval `g.findfile element=cell file=$infile`
-filename="${fullname}"
-BASE="${name}"
-if [ "$filename" = "" ] ; then
+eval `g.findfile element=cell file="$infile"`
+filename="$fullname"
+BASE="$name"
+if [ -z "$filename" ] ; then
g.message -e "Raster map <$infile> not found"
exit 1
else
infile="$filename"
fi
-eval `g.findfile element=cell file=$file2`
+eval `g.findfile element=cell file="$file2"`
filename2="${fullname}"
-BASE="${name}"
+BASE="$name"
if test "$filename2" ; then
g.message -e "Temporal raster map <$filename2> exists"
exit 1
@@ -148,12 +148,18 @@
# else
if test $op = 0; then
g.message "Generating a reclass rules file with area size less than or equal to $limit hectares..."
- r.stats -aln in=$file2,$infile fs='|' | awk -F'|' '{limit='$limit'; hectares=$5 * 0.0001;
- {if (hectares <= limit) printf("%d = %d %s\n",$1,$3,$4)}}' > "$infile.rules"
+ r.stats -aln in="$file2","$infile" fs='|' | \
+ awk -F'|' -v LIM="$limit" \
+ '{hectares=$5 * 0.0001;
+ {if (hectares <= LIM)
+ printf("%d = %d %s\n",$1,$3,$4) } }' > "$infile.rules"
else
g.message "Generating a reclass rules file with area size greater than or equal to $limit hectares..."
- r.stats -aln in=$file2,$infile fs='|' | awk -F'|' '{limit='$limit'; hectares=$5 * 0.0001;
- {if (hectares >= limit) printf("%d = %d %s\n",$1,$3,$4)}}' > "$infile.rules"
+ r.stats -aln in="$file2","$infile" fs='|' | \
+ awk -F'|' -v LIM="$limit" \
+ '{hectares=$5 * 0.0001;
+ {if (hectares >= LIM)
+ printf("%d = %d %s\n",$1,$3,$4) } }' > "$infile.rules"
fi
#fi
@@ -162,7 +168,7 @@
fi
g.message "Generating output raster map <$outfile>..."
cat "$infile.rules" | r.reclass i="$file2" o="$outfile.recl"
-r.mapcalc "$outfile=$outfile.recl"
+r.mapcalc "$outfile = $outfile.recl"
g.remove rast="$outfile.recl","$file2" --quiet
#####cleanup
Modified: grass/branches/develbranch_6/scripts/v.dissolve/v.dissolve
===================================================================
--- grass/branches/develbranch_6/scripts/v.dissolve/v.dissolve 2011-03-09 06:01:52 UTC (rev 45610)
+++ grass/branches/develbranch_6/scripts/v.dissolve/v.dissolve 2011-03-09 06:42:07 UTC (rev 45611)
@@ -85,7 +85,7 @@
trap "exitprocedure" 2 3 15
# does map exist?
-eval `g.findfile element=vector file=$GIS_OPT_INPUT`
+eval `g.findfile element=vector file="$GIS_OPT_INPUT"`
if [ ! "$file" ] ; then
g.message -e "Vector map <$GIS_OPT_INPUT> not found"
exit 1
@@ -102,7 +102,7 @@
exit 1
fi
- table=`v.db.connect $GIS_OPT_INPUT -g fs=";" | grep -w "^$GIS_OPT_LAYER" | awk -F ";" '{print $2}'`
+ table=`v.db.connect "$GIS_OPT_INPUT" -gl fs="|" layer="$GIS_OPT_LAYER" | cut -f2 -d'|'`
if [ -z "$table" ] ; then
g.message -e "Database connection not defined for layer $GIS_OPT_LAYER"
exit 1
@@ -116,7 +116,7 @@
# write cmd history:
-v.support ${GIS_OPT_OUTPUT} cmdhist="${CMDLINE}"
+v.support "$GIS_OPT_OUTPUT" cmdhist="${CMDLINE}"
exit 0
More information about the grass-commit
mailing list