[GRASS-SVN] r60488 - grass/branches/releasebranch_7_0/raster/r.contour

svn_grass at osgeo.org svn_grass at osgeo.org
Sun May 25 15:05:46 PDT 2014


Author: annakrat
Date: 2014-05-25 15:05:46 -0700 (Sun, 25 May 2014)
New Revision: 60488

Modified:
   grass/branches/releasebranch_7_0/raster/r.contour/main.c
Log:
r.contour: flag to not create attribute table, #2201 (merged from trunk, r60381,r60386)

Modified: grass/branches/releasebranch_7_0/raster/r.contour/main.c
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.contour/main.c	2014-05-25 21:49:16 UTC (rev 60487)
+++ grass/branches/releasebranch_7_0/raster/r.contour/main.c	2014-05-25 22:05:46 UTC (rev 60488)
@@ -61,6 +61,7 @@
     struct Option *max;
     struct Option *step;
     struct Option *cut;
+    struct Flag *notable;
 
     int i;
 
@@ -130,6 +131,8 @@
     cut->description =
 	_("Minimum number of points for a contour line (0 -> no limit)");
 
+    notable = G_define_standard_flag(G_FLG_V_TABLE);
+
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
@@ -152,41 +155,43 @@
     Vect_open_new(&Map, vect->answer, 1);
     Vect_hist_command(&Map);
 
-    db_init_string(&sql);
-
-    /* Open database, create table */
-    Fi = Vect_default_field_info(&Map, 1, NULL, GV_1TABLE);
-    Vect_map_add_dblink(&Map, Fi->number, Fi->name, Fi->table, Fi->key,
-			Fi->database, Fi->driver);
-
-    Driver =
-	db_start_driver_open_database(Fi->driver,
-				      Vect_subst_var(Fi->database, &Map));
-    if (Driver == NULL)
-	G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
-		      Fi->database, Fi->driver);
-
-    sprintf(buf, "create table %s ( cat integer, level double precision )",
-	    Fi->table);
-
-    db_set_string(&sql, buf);
-
-    G_debug(1, "SQL: %s", db_get_string(&sql));
-
-    if (db_execute_immediate(Driver, &sql) != DB_OK) {
-	G_fatal_error(_("Unable to create table: '%s'"),
-		      db_get_string(&sql));
+    if (!notable->answer) {
+        db_init_string(&sql);
+    
+        /* Open database, create table */
+        Fi = Vect_default_field_info(&Map, 1, NULL, GV_1TABLE);
+        Vect_map_add_dblink(&Map, Fi->number, Fi->name, Fi->table, Fi->key,
+                            Fi->database, Fi->driver);
+    
+        Driver =
+            db_start_driver_open_database(Fi->driver,
+                                          Vect_subst_var(Fi->database, &Map));
+        if (Driver == NULL)
+            G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
+                          Fi->database, Fi->driver);
+    
+        sprintf(buf, "create table %s ( cat integer, level double precision )",
+                Fi->table);
+    
+        db_set_string(&sql, buf);
+    
+        G_debug(1, "SQL: %s", db_get_string(&sql));
+    
+        if (db_execute_immediate(Driver, &sql) != DB_OK) {
+            G_fatal_error(_("Unable to create table: '%s'"),
+                          db_get_string(&sql));
+        }
+    
+        if (db_create_index2(Driver, Fi->table, Fi->key) != DB_OK)
+            G_warning(_("Unable to create index for table <%s>, key <%s>"),
+                      Fi->table, Fi->key);
+    
+        if (db_grant_on_table
+            (Driver, Fi->table, DB_PRIV_SELECT, DB_GROUP | DB_PUBLIC) != DB_OK)
+            G_fatal_error(_("Unable to grant privileges on table <%s>"),
+                          Fi->table);
     }
 
-    if (db_create_index2(Driver, Fi->table, Fi->key) != DB_OK)
-	G_warning(_("Unable to create index for table <%s>, key <%s>"),
-		  Fi->table, Fi->key);
-
-    if (db_grant_on_table
-	(Driver, Fi->table, DB_PRIV_SELECT, DB_GROUP | DB_PUBLIC) != DB_OK)
-	G_fatal_error(_("Unable to grant privileges on table <%s>"),
-		      Fi->table);
-
     z_array = get_z_array(fd, Wind.rows, Wind.cols);
     lev = getlevels(levels, max, min, step, &range, &nlevels);
     displaceMatrix(z_array, Wind.rows, Wind.cols, lev, nlevels);
@@ -196,22 +201,23 @@
     G_message(_("Writing attributes..."));
     /* Write levels */
 
-    db_begin_transaction(Driver);
-    for (i = 0; i < nlevels; i++) {
-	sprintf(buf, "insert into %s values ( %d, %e )", Fi->table, i + 1,
-		lev[i]);
-	db_set_string(&sql, buf);
-
-	G_debug(3, "SQL: %s", db_get_string(&sql));
-
-	if (db_execute_immediate(Driver, &sql) != DB_OK) {
-	    G_fatal_error(_("Unable to insert new record: '%s'"), db_get_string(&sql));
-	}
+    if (!notable->answer) {
+        db_begin_transaction(Driver);
+        for (i = 0; i < nlevels; i++) {
+            sprintf(buf, "insert into %s values ( %d, %e )", Fi->table, i + 1,
+                    lev[i]);
+            db_set_string(&sql, buf);
+            
+            G_debug(3, "SQL: %s", db_get_string(&sql));
+            
+            if (db_execute_immediate(Driver, &sql) != DB_OK) {
+                G_fatal_error(_("Unable to insert new record: '%s'"), db_get_string(&sql));
+            }
+        }
+        db_commit_transaction(Driver);
+        
+        db_close_database_shutdown_driver(Driver);
     }
-    db_commit_transaction(Driver);
-
-    db_close_database_shutdown_driver(Driver);
-
     Vect_build(&Map);
     Vect_close(&Map);
 



More information about the grass-commit mailing list