[GRASS-dev] v.what.rast patch: where statement added
Markus Neteler
neteler at itc.it
Tue Jan 30 12:27:43 EST 2007
Hi,
I have a map of tick sampling sites and a few sites
are lacking the elevation. Only those I want to update
from a DEM which is easily done with v.what.rast.
I have added a where= statement to the program (patch
attached) which works as it is rather trivial.
The only issue is that the program states at the end:
...
25 categories loaded from table
24 categories loaded from vector
0 categories from vector missing in table
0 duplicate categories in vector
24 records updated
0 update errors
In case the user uses where="height=0"
then "XX records updated" is wrong as it is calculated
on the base of geometry, not DBMI events.
My patch contains a dirty deactivation of this message
in case where= is used. Of course it would be nicer to
see the actual number there.
Any ideas?
Markus
-------------- next part --------------
? OBJ.x86_64-unknown-linux-gnu
Index: main.c
===================================================================
RCS file: /grassrepository/grass6/vector/v.what.rast/main.c,v
retrieving revision 1.19
diff -u -r1.19 main.c
--- main.c 28 Oct 2006 20:33:34 -0000 1.19
+++ main.c 30 Jan 2007 17:17:32 -0000
@@ -49,7 +49,7 @@
DCELL *dcell;
double drow, dcol;
char buf[2000];
- struct Option *vect_opt, *rast_opt, *field_opt, *col_opt;
+ struct Option *vect_opt, *rast_opt, *field_opt, *col_opt, *where_opt;
int Cache_size;
struct order *cache;
int cur_row;
@@ -96,6 +96,8 @@
col_opt->required = YES ;
col_opt->description= _("Column name (will be updated by raster values)") ;
+ where_opt = G_define_standard_option(G_OPT_WHERE);
+
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
@@ -309,10 +311,14 @@
}
db_append_string ( &stmt, buf );
- sprintf (buf, " where %s = %d", Fi->key, cache[point].cat);
+ sprintf (buf, " where %s = %d", Fi->key, cache[point].cat);
db_append_string ( &stmt, buf );
-
- G_debug ( 3, db_get_string (&stmt) );
+ /* user provides where condition: */
+ if (where_opt->answer) {
+ sprintf(buf, " AND %s", where_opt->answer);
+ db_append_string ( &stmt, buf );
+ }
+ G_debug ( 0, db_get_string (&stmt) );
/* Update table */
if ( db_execute_immediate (driver, &stmt) == DB_OK ){
@@ -332,7 +338,7 @@
G_message ( _("%d categories loaded from vector"), point_cnt );
G_message ( _("%d categories from vector missing in table"), norec_cnt );
G_message ( _("%d duplicate categories in vector"), dupl_cnt );
- G_message ( _("%d records updated"), update_cnt );
+ if (! where_opt->answer) G_message ( _("%d records updated"), update_cnt );
G_message ( _("%d update errors"), upderr_cnt );
exit(EXIT_SUCCESS);
More information about the grass-dev
mailing list