[GRASS-SVN] r60381 - grass/trunk/raster/r.contour
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue May 20 19:32:41 PDT 2014
Author: annakrat
Date: 2014-05-20 19:32:41 -0700 (Tue, 20 May 2014)
New Revision: 60381
Modified:
grass/trunk/raster/r.contour/main.c
Log:
r.contour: flag to not create attribute table, #2201
Modified: grass/trunk/raster/r.contour/main.c
===================================================================
--- grass/trunk/raster/r.contour/main.c 2014-05-21 02:31:19 UTC (rev 60380)
+++ grass/trunk/raster/r.contour/main.c 2014-05-21 02:32:41 UTC (rev 60381)
@@ -61,6 +61,7 @@
struct Option *max;
struct Option *step;
struct Option *cut;
+ struct Flag *notable;
int i;
@@ -130,6 +131,10 @@
cut->description =
_("Minimum number of points for a contour line (0 -> no limit)");
+ notable = G_define_flag();
+ notable->key = 't';
+ notable->description = _("Do not create attribute table");
+
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
@@ -154,41 +159,43 @@
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);
@@ -198,22 +205,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