[GRASS5] [PATCH] introduce where clause in d.vect.thematic (and v.univar.sh)

Moritz Lennert mlennert at club.worldonline.be
Tue Sep 6 16:30:41 EDT 2005


Hi,

Attached two patches for introducing a 'where' clause in d.vect.thematic (and
v.univar.sh). This allows to display (and classify) only part of a vector map.

Any objections to me committing this ?

Moritz
-------------- next part --------------
Index: d.vect.thematic
===================================================================
RCS file: /grassrepository/grass6/scripts/d.vect.thematic/d.vect.thematic,v
retrieving revision 1.17
diff -u -r1.17 d.vect.thematic
--- d.vect.thematic	5 Sep 2005 17:27:57 -0000	1.17
+++ d.vect.thematic	6 Sep 2005 20:17:30 -0000
@@ -142,6 +142,12 @@
 #% description: Name of group file where thematic map commands will be saved
 #% required : no
 #%end
+#%option
+#% key: where
+#% type: string
+#% description: WHERE conditions of SQL statement without 'where' keyword
+#% required : no
+#%end
 #%flag
 #% key: u
 #% description: Update color values to GRASSRGB column in attribute table
@@ -292,7 +298,12 @@
 echo "Group $group" > "$TMP3"
 
 # Calculate statistics for thematic intervals
-v.univar.sh -e database=$database table=$table column=$GIS_OPT_column > "$TMP1"
+if [ -z "$GIS_OPT_where" ] ; then
+  v.univar.sh -e database=$database table=$table column=$GIS_OPT_column > "$TMP1"
+else
+  v.univar.sh -e database=$database table=$table column=$GIS_OPT_column where="$GIS_OPT_where" > "$TMP1"
+fi
+  
 min="`grep 'Minimum:' $TMP1 | sed s/Minimum://`"
 max="`grep 'Maximum:' $TMP1 | sed s/Maximum://`"
 mean="`grep 'Mean:' $TMP1 | sed s/Mean://`"
@@ -505,8 +516,13 @@
         echo "text $openbracket$rangemin - $rangemax$closebracket $extranote"  >> "$TMP2"
 
         echo $themecolor@$rangemin@$rangemax@$extranote@$openbracket@$closebracket | awk -F@ '{print $1 "\t\t" $5$2" - "$3$6" "$4}'
+	if [ -z "$GIS_OPT_where" ] ; then
+            sqlwhere="$GIS_OPT_column $mincomparison $rangemin and $GIS_OPT_column<=$rangemax"
+	else
+            sqlwhere="$GIS_OPT_column $mincomparison $rangemin and $GIS_OPT_column<=$rangemax AND $GIS_OPT_where"
+	fi
+
         # update color to database?
-        sqlwhere="$GIS_OPT_column $mincomparison $rangemin and $GIS_OPT_column<=$rangemax"
         if [ $GIS_FLAG_u -eq 1 ] ; then
             echo "UPDATE $table SET GRASSRGB = '$themecolor' WHERE\
                 $sqlwhere" | db.execute database=$database
@@ -681,8 +697,13 @@
 
         echo $ptsize@$rangemin@$rangemax@$extranote@$openbracket@$closebracket | awk -F@ '{print $1 "\t\t" $5$2" - "$3$6" "$4}'
 
+	if [ -z "$GIS_OPT_where" ] ; then
+           sqlwhere="$GIS_OPT_column $mincomparison $rangemin and $GIS_OPT_column<=$rangemax"
+	else
+           sqlwhere="$GIS_OPT_column $mincomparison $rangemin and $GIS_OPT_column<=$rangemax AND $GIS_OPT_where"
+	fi
+
         # update color to database?
-        sqlwhere="$GIS_OPT_column $mincomparison $rangemin and $GIS_OPT_column<=$rangemax"
         if [ $GIS_FLAG_u -eq 1 ] ; then
             echo "UPDATE $table SET GRASSRGB = '$themecolor' WHERE\
                 $sqlwhere" | db.execute database=$database
-------------- next part --------------
Index: v.univar.sh
===================================================================
RCS file: /grassrepository/grass6/scripts/v.univar.sh/v.univar.sh,v
retrieving revision 1.10
diff -u -r1.10 v.univar.sh
--- v.univar.sh	31 Aug 2005 14:21:49 -0000	1.10
+++ v.univar.sh	6 Sep 2005 20:18:35 -0000
@@ -46,6 +46,12 @@
 #% description: Database driver
 #% required : no
 #%end
+#%option
+#% key: where
+#% type: string
+#% description: WHERE conditions of SQL statement without 'where' keyword
+#% required : no
+#%end
 
 if  [ -z $GISBASE ] ; then
     echo "You must be in GRASS GIS to run this program."
@@ -105,7 +111,12 @@
     drv="driver=$GIS_OPT_driver"
 fi
 
-db.select table=$GIS_OPT_table $db $drv sql="select $GIS_OPT_column from $GIS_OPT_table" -c > "$TMP"
+if [ -z "$GIS_OPT_where" ] ; then
+   db.select table=$GIS_OPT_table $db $drv sql="select $GIS_OPT_column from $GIS_OPT_table" -c > "$TMP"
+else
+   db.select table=$GIS_OPT_table $db $drv sql="select $GIS_OPT_column from $GIS_OPT_table WHERE $GIS_OPT_where" -c > "$TMP"
+fi
+
 
 echo "database = $GIS_OPT_database"
 echo "db = $db"


More information about the grass-dev mailing list