[GRASS-SVN] r34751 - grass/branches/develbranch_6/vector/v.to.db

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Dec 6 11:37:35 EST 2008


Author: martinl
Date: 2008-12-06 11:37:35 -0500 (Sat, 06 Dec 2008)
New Revision: 34751

Modified:
   grass/branches/develbranch_6/vector/v.to.db/areas.c
   grass/branches/develbranch_6/vector/v.to.db/lines.c
   grass/branches/develbranch_6/vector/v.to.db/main.c
   grass/branches/develbranch_6/vector/v.to.db/parse.c
   grass/branches/develbranch_6/vector/v.to.db/query.c
   grass/branches/develbranch_6/vector/v.to.db/report.c
   grass/branches/develbranch_6/vector/v.to.db/update.c
Log:
v.to.db: don't report cat -1
	 message/parameters cosmetics


Modified: grass/branches/develbranch_6/vector/v.to.db/areas.c
===================================================================
--- grass/branches/develbranch_6/vector/v.to.db/areas.c	2008-12-06 16:25:20 UTC (rev 34750)
+++ grass/branches/develbranch_6/vector/v.to.db/areas.c	2008-12-06 16:37:35 UTC (rev 34751)
@@ -1,6 +1,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
+#include <grass/glocale.h>
+
 #include "global.h"
 
 /* This function now does one of 3 things:
@@ -22,6 +24,9 @@
 
     Cats = Vect_new_cats_struct();
     nareas = Vect_get_num_areas(Map);
+
+    G_message(_("Reading areas..."));
+
     /* Cycle through all areas */
     for (area_num = 1; area_num <= nareas; area_num++) {
 	Ppoints = Vect_new_line_struct();
@@ -72,6 +77,7 @@
 		}
 	    }
 	}
+	G_percent(area_num, nareas, 2);
     }
 
     return 0;

Modified: grass/branches/develbranch_6/vector/v.to.db/lines.c
===================================================================
--- grass/branches/develbranch_6/vector/v.to.db/lines.c	2008-12-06 16:25:20 UTC (rev 34750)
+++ grass/branches/develbranch_6/vector/v.to.db/lines.c	2008-12-06 16:37:35 UTC (rev 34751)
@@ -1,5 +1,7 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <grass/glocale.h>
+
 #include "global.h"
 
 /* Read area cats for one side 
@@ -69,6 +71,8 @@
     LCats = Vect_new_cats_struct();
     RCats = Vect_new_cats_struct();
 
+    G_message(_("Reading features..."));
+    
     /* Cycle through all lines */
     nlines = Vect_get_num_lines(Map);
     for (line_num = 1; line_num <= nlines; line_num++) {
@@ -265,6 +269,7 @@
 		Values[idx].d1 = len / dist;
 	    }
 	}
+	G_percent(line_num, nlines, 2);
     }
 
     return 0;

Modified: grass/branches/develbranch_6/vector/v.to.db/main.c
===================================================================
--- grass/branches/develbranch_6/vector/v.to.db/main.c	2008-12-06 16:25:20 UTC (rev 34750)
+++ grass/branches/develbranch_6/vector/v.to.db/main.c	2008-12-06 16:37:35 UTC (rev 34751)
@@ -30,7 +30,7 @@
 
     module = G_define_module();
     module->keywords = _("vector, database, attribute table");
-    module->description = _("Populate database values from vector features.");
+    module->description = _("Populates database values from vector features.");
 
     parse_command_line(argc, argv);
 
@@ -44,7 +44,8 @@
     Fi = Vect_get_field(&Map, options.field);
 
     if (!options.print && Fi == NULL) {
-	G_fatal_error(_("Database connection not defined for layer %d. Use v.db.connect first."),
+	G_fatal_error(_("Database connection not defined for layer %d. "
+			"Use v.db.connect first."),
 		      options.field);
     }
 

Modified: grass/branches/develbranch_6/vector/v.to.db/parse.c
===================================================================
--- grass/branches/develbranch_6/vector/v.to.db/parse.c	2008-12-06 16:25:20 UTC (rev 34750)
+++ grass/branches/develbranch_6/vector/v.to.db/parse.c	2008-12-06 16:37:35 UTC (rev 34751)
@@ -33,16 +33,18 @@
     parms.type = G_define_standard_option(G_OPT_V_TYPE);
     parms.type->options = "point,line,boundary,centroid";
     parms.type->answer = "point,line,boundary,centroid";
+    parms.type->label = _("Feature type");
     parms.type->description =
-	_("Type of elements (for coor valid point/centroid, "
-	  "for length valid line/boundary)");
-    parms.type->label = _("Type of elements");
+	_("For coor valid point/centroid, "
+	  "for length valid line/boundary");
 
     parms.field = G_define_standard_option(G_OPT_V_FIELD);
+    parms.field->label = _("Layer number (write to)");
 
     parms.qfield = G_define_standard_option(G_OPT_V_FIELD);
     parms.qfield->key = "qlayer";
-    parms.qfield->label = _("Query layer (used by 'query' option)");
+    parms.qfield->label = _("Query layer number (read from)");
+    parms.qfield->guisection = _("Query");
 
     parms.option = G_define_option();
     parms.option->key = "option";
@@ -85,10 +87,15 @@
 
     parms.col = G_define_standard_option(G_OPT_COLUMNS);
 
-    parms.qcol = G_define_standard_option(G_OPT_COLUMN);
+    parms.qcol = G_define_option();
     parms.qcol->key = "qcolumn";
     parms.qcol->label = _("Name of attribute column used for 'query' option");
     parms.qcol->description = _("E.g. 'cat', 'count(*)', 'sum(val)'");
+    parms.qcol->type = TYPE_STRING;
+    parms.qcol->key_desc = "name";
+    parms.qcol->required = NO;
+    parms.qcol->multiple = NO;
+    parms.qcol->guisection = _("Query");
 
     flags.p = G_define_flag();
     flags.p->key = 'p';
@@ -97,7 +104,7 @@
 
     flags.s = G_define_flag();
     flags.s->key = 's';
-    flags.s->description = _("Only print sql statements");
+    flags.s->description = _("Only print SQL statements");
     flags.s->guisection = _("Print");
 
     flags.t = G_define_flag();

Modified: grass/branches/develbranch_6/vector/v.to.db/query.c
===================================================================
--- grass/branches/develbranch_6/vector/v.to.db/query.c	2008-12-06 16:25:20 UTC (rev 34750)
+++ grass/branches/develbranch_6/vector/v.to.db/query.c	2008-12-06 16:37:35 UTC (rev 34751)
@@ -20,12 +20,11 @@
     Points = Vect_new_line_struct();
     Cats = Vect_new_cats_struct();
 
+    G_message(_("Reading features..."));
+
     /* Cycle through all lines and make a list of categories of 'qfield' for each category given by 'field' */
-    G_message(_("Reading data from the map..."));
     nlines = Vect_get_num_lines(Map);
     for (line_num = 1; line_num <= nlines; line_num++) {
-	G_percent(line_num, nlines, 1);
-
 	type = Vect_read_line(Map, Points, Cats, line_num);
 	if (!(type & options.type))
 	    continue;
@@ -73,6 +72,8 @@
 		}
 	    }
 	}
+
+	G_percent(line_num, nlines, 2);
     }
 
     db_init_string(&stmt);

Modified: grass/branches/develbranch_6/vector/v.to.db/report.c
===================================================================
--- grass/branches/develbranch_6/vector/v.to.db/report.c	2008-12-06 16:25:20 UTC (rev 34750)
+++ grass/branches/develbranch_6/vector/v.to.db/report.c	2008-12-06 16:37:35 UTC (rev 34751)
@@ -172,18 +172,22 @@
 int print_stat(void)
 {
     if (vstat.rcat > 0)
-	G_message(_("%d categories read from map"), vstat.rcat);
+	G_message(_("%d categories read from vector map (layer %d)"),
+		  vstat.rcat - 1, options.field); /* don't report cat -1 */
     if (vstat.select > 0)
-	G_message(_("%d records selected from table"), vstat.select);
+	G_message(_("%d records selected from table (layer %d)"),
+		  vstat.select, options.qfield);
     if (vstat.exist > 0)
-	G_message(_("%d categories read from map exist in selection from table"),
+	G_message(_("%d categories read from vector map exist in selection from table"),
 		  vstat.exist);
     if (vstat.notexist > 0)
-	G_message(_("%d categories read from map don't exist in selection from table"),
+	G_message(_("%d categories read from vector map don't exist in selection from table"),
 		  vstat.notexist);
-    G_message(_("%d records updated/inserted"), vstat.update);
+    G_message(_("%d records updated/inserted (layer %d)"),
+	      vstat.update, options.field);
     if (vstat.error > 0)
-	G_message(_("%d update/insert errors"), vstat.error);
+	G_message(_("%d update/insert errors (layer %d)"),
+		  vstat.error, options.field);
     if (vstat.dupl > 0)
 	G_message(_("%d categories with more points (coordinates not loaded)"),
 		  vstat.dupl);

Modified: grass/branches/develbranch_6/vector/v.to.db/update.c
===================================================================
--- grass/branches/develbranch_6/vector/v.to.db/update.c	2008-12-06 16:25:20 UTC (rev 34750)
+++ grass/branches/develbranch_6/vector/v.to.db/update.c	2008-12-06 16:37:35 UTC (rev 34751)
@@ -43,7 +43,7 @@
     db_begin_transaction(driver);
 
     /* select existing categories to array (array is sorted) */
-    vstat.select = db_select_int(driver, qFi->table, Fi->key, NULL, &catexst);
+    vstat.select = db_select_int(driver, qFi->table, qFi->key, NULL, &catexst);
     G_debug(3, "Existing categories: %d", vstat.select);
 
     /* create beginning of stmt */
@@ -73,8 +73,6 @@
     /* update */
     G_message(_("Updating database..."));
     for (i = 0; i < vstat.rcat; i++) {
-	G_percent(i + 1, vstat.rcat, 1);
-
 	fcat = Values[i].cat;
 	if (fcat < 0)
 	    continue;
@@ -103,7 +101,7 @@
 	case O_START:
 	case O_END:
 	    if (Values[i].count1 > 1) {
-		G_warning(_("More elements of category [%d], nothing loaded to DB"),
+		G_warning(_("More elements of category %d, nothing loaded to database"),
 			  Values[i].cat);
 		vstat.dupl++;
 		continue;
@@ -186,23 +184,23 @@
 		    break;
 		}
 	    }
+	    G_percent(i + 1, vstat.rcat, 2);
 	}
 
 	G_debug(3, "SQL: %s", buf2);
 	db_set_string(&stmt, buf2);
 
-	/* category exist in DB ? */
-	cex =
-	    (int *)bsearch((void *)&fcat, catexst, vstat.select, sizeof(int),
-			   srch);
-
+	/* category exist in DB table ? */
+	cex = (int *)bsearch((void *)&fcat, catexst, vstat.select, sizeof(int),
+			     srch);
+	
 	if (options.option == O_CAT) {
 	    if (cex == NULL) {	/* cat does not exist in DB */
 		upd = 1;
 		vstat.notexist++;
 	    }
 	    else {		/* cat exists in DB */
-		G_warning(_("Cat [%d]: row already exists (not inserted)"),
+		G_warning(_("Record (cat %d) already exists (not inserted)"),
 			  fcat);
 		upd = 0;
 		vstat.exist++;
@@ -210,7 +208,7 @@
 	}
 	else {
 	    if (cex == NULL) {	/* cat does not exist in DB */
-		G_warning(_("Cat [%d]: row does not exist (not updated)"),
+		G_warning(_("Record (cat %d) does not exist (not updated)"),
 			  fcat);
 		upd = 0;
 		vstat.notexist++;
@@ -239,6 +237,7 @@
     db_commit_transaction(driver);
 
     G_free(catexst);
+    
     db_close_database_shutdown_driver(driver);
     db_free_string(&stmt);
 



More information about the grass-commit mailing list