[GRASS-SVN] r42838 - grass/branches/develbranch_6/scripts/v.rast.stats

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jul 19 03:21:08 EDT 2010


Author: hamish
Date: 2010-07-19 07:21:08 +0000 (Mon, 19 Jul 2010)
New Revision: 42838

Modified:
   grass/branches/develbranch_6/scripts/v.rast.stats/v.rast.stats
Log:
cleanup quoting for some variables, add some debug messages, SUS-compatible grep flags


Modified: grass/branches/develbranch_6/scripts/v.rast.stats/v.rast.stats
===================================================================
--- grass/branches/develbranch_6/scripts/v.rast.stats/v.rast.stats	2010-07-18 19:39:24 UTC (rev 42837)
+++ grass/branches/develbranch_6/scripts/v.rast.stats/v.rast.stats	2010-07-19 07:21:08 UTC (rev 42838)
@@ -174,10 +174,10 @@
 
 #Temporarily setting raster resolution to $RASTER resolution
 #keep boundary settings
-g.region nsres=$NSRES ewres=$EWRES -a
+g.region nsres="$NSRES" ewres="$EWRES" -a
 
 #prepare raster MASK
-v.to.rast in="$VECTOR" out="${VECTOR}_${TMPNAME}" use=cat --quiet
+v.to.rast in="$VECTOR" out="${VECTOR}_$TMPNAME" use=cat --quiet
 if [ $? -ne 0 ] ; then
    g.message -e "An error occurred while converting vector to raster"
    cleanup
@@ -186,7 +186,7 @@
 
 
 #dump cats to file to avoid "too many argument" problem:
-r.category "${VECTOR}_${TMPNAME}" fs=';' --quiet | cut -d';' -f1 > "$TEMPFILE.cats"
+r.category "${VECTOR}_$TMPNAME" fs=';' --quiet | cut -d';' -f1 > "$TEMPFILE.cats"
 #echo "List of categories found: $CATSLIST"
 NUMBER=`cat "$TEMPFILE.cats" | wc -l | awk '{print $1}'`
 if [ $NUMBER -lt 1 ] ; then
@@ -207,7 +207,7 @@
    DBFDRIVER=0
 fi
 
-if [ $DBFDRIVER -eq 1 ] ; then
+if [ "$DBFDRIVER" -eq 1 ] ; then
    # `wc -c` reports number of chars + 1 for the newline
    if [ `echo "$COLPREFIX" | wc -c` -gt 7 ] ; then
        g.message -e "Cannot create unique names for columns. \
@@ -220,7 +220,10 @@
 
 # we need this for non-DBF driver:
 DB_SQLDRIVER=`v.db.connect -g "$VECTOR" fs=";" | cut -d';' -f5`
+g.message -d message="sql driver: [$DB_SQLDRIVER]"
+
 DB_DATABASE="`v.db.connect -g "$VECTOR" fs=";" | cut -d';' -f4`"
+g.message -d message="database: [$DB_DATABASE]"
 
 #Find out which table is linked to the vector map on the given layer
 TABLE=`v.db.connect map="$VECTOR" -g fs=";" | grep -w "^$GIS_OPT_LAYER" | awk -F ";" '{print $2}'`
@@ -228,14 +231,15 @@
    g.message -e 'There is no table connected to this map! Run v.db.connect or v.db.addtable first.'
    exit 1
 fi
+g.message -d message="table: [$TABLE]"
 
 
 BASECOLS="n min max range mean stddev variance cf_var sum"
 
 # do extended stats?
-if [ $GIS_FLAG_E -eq 1 ] ; then
+if [ "$GIS_FLAG_E" -eq 1 ] ; then
    # namespace is limited in DBF but the % value is important
-   if [ $DBFDRIVER -eq 1 ] ; then
+   if [ "$DBFDRIVER" -eq 1 ] ; then
       PERCCOL="per$GIS_OPT_PERCENTILE"
    else
       PERCCOL="percentile_$GIS_OPT_PERCENTILE"
@@ -249,15 +253,16 @@
 unset ADDCOLS
 for i in $BASECOLS $EXTRACOLS ; do
   #check if column already present
-  if [ $DBFDRIVER -eq 1 ] ; then
-     CURRCOLUMN="`echo "${COLPREFIX}_${i}" | cut -b1-10`"
+  if [ "$DBFDRIVER" -eq 1 ] ; then
+     CURRCOLUMN="`echo "${COLPREFIX}_$i" | cut -b1-10`"
   else
-     CURRCOLUMN="${COLPREFIX}_${i}"
+     CURRCOLUMN="${COLPREFIX}_$i"
   fi
-  v.info -c $VECTOR --quiet | sed 's+^+|+g' | sed 's+$+|+g' | \
-    grep "|$CURRCOLUMN|" --quiet
+  g.message -d message="Looking for <$CURRCOLUMN> in <$VECTOR> ..."
+  v.info -c "$VECTOR" --quiet | sed -e 's+^+|+' -e 's+$+|+' | \
+    grep "|$CURRCOLUMN|" -q
   if [ $? -eq 0 ] ; then
-    if [ $GIS_FLAG_C -ne 1 ] ; then
+    if [ "$GIS_FLAG_C" -ne 1 ] ; then
        g.message -e "Cannot create column <$CURRCOLUMN> (already present). \
          Use -c flag to update values in this column."
        cleanup
@@ -319,11 +324,11 @@
       eval value=\${$var}
 
       if [ $DBFDRIVER -eq 1 ] ; then
-	colname="`echo "${COLPREFIX}_${var}" | cut -b1-10`"
+	colname="`echo "${COLPREFIX}_$var" | cut -b1-10`"
       else
-	colname="${COLPREFIX}_${var}"
+	colname="${COLPREFIX}_$var"
       fi
-
+      g.message -d debug=3 message="UPDATE $TABLE SET ${colname}=${value} WHERE cat=$i;"
       echo "UPDATE $TABLE SET ${colname}=${value} WHERE cat=$i;" >> "$SQLTMP"
    done
 
@@ -332,7 +337,7 @@
 
 
 g.message "Updating the database ..."
-db.execute input="$SQLTMP" database="${DB_DATABASE}" driver="$DB_SQLDRIVER"
+db.execute input="$SQLTMP" database="$DB_DATABASE" driver="$DB_SQLDRIVER"
 EXITCODE=$?
 
 



More information about the grass-commit mailing list