[GRASS-SVN] r52083 - grass/branches/develbranch_6/vector/v.in.db
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jun 15 09:34:40 PDT 2012
Author: mlennert
Date: 2012-06-15 09:34:40 -0700 (Fri, 15 Jun 2012)
New Revision: 52083
Modified:
grass/branches/develbranch_6/vector/v.in.db/main.c
Log:
add flag to allow reusing imported table as attribute table (to be tested)
Modified: grass/branches/develbranch_6/vector/v.in.db/main.c
===================================================================
--- grass/branches/develbranch_6/vector/v.in.db/main.c 2012-06-15 16:32:58 UTC (rev 52082)
+++ grass/branches/develbranch_6/vector/v.in.db/main.c 2012-06-15 16:34:40 UTC (rev 52083)
@@ -34,6 +34,7 @@
struct Option *driver_opt, *database_opt, *table_opt;
struct Option *xcol_opt, *ycol_opt, *zcol_opt, *keycol_opt, *where_opt,
*outvect;
+ struct Flag *same_table_flag;
struct GModule *module;
struct Map_info Map;
struct line_pnts *Points;
@@ -59,11 +60,11 @@
driver_opt = G_define_standard_option(G_OPT_DRIVER);
driver_opt->options = db_list_drivers();
- driver_opt->answer = (char *) db_get_default_driver_name();
+ driver_opt->answer = (char *)db_get_default_driver_name();
driver_opt->guisection = _("Connection");
database_opt = G_define_standard_option(G_OPT_DATABASE);
- database_opt->answer = (char *) db_get_default_database_name();
+ database_opt->answer = (char *)db_get_default_database_name();
database_opt->guisection = _("Connection");
xcol_opt = G_define_standard_option(G_OPT_COLUMN);
@@ -90,6 +91,12 @@
outvect = G_define_standard_option(G_OPT_V_OUTPUT);
+ same_table_flag = G_define_flag();
+ same_table_flag->key = 't';
+ same_table_flag->guisection = _("Connection");
+ same_table_flag->description =
+ _("Use imported table as attribute table for new map");
+
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
@@ -168,7 +175,7 @@
nrows = db_get_num_rows(&cursor);
G_debug(2, "%d points selected", nrows);
-
+
count = 0;
G_message(_("Writing features..."));
while (db_fetch(&cursor, DB_NEXT, &more) == DB_OK && more) {
@@ -192,7 +199,7 @@
else
coor[i] = db_get_value_double(value);
}
-
+
Vect_reset_line(Points);
Vect_reset_cats(Cats);
@@ -210,23 +217,31 @@
/* Copy table */
G_message(_("Copying attributes..."));
- if (where_opt->answer)
- ret =
- db_copy_table_where(driver_opt->answer, database_opt->answer,
- table_opt->answer, fi->driver, fi->database,
- fi->table, where_opt->answer);
- else
- ret =
- db_copy_table(driver_opt->answer, database_opt->answer,
- table_opt->answer, fi->driver, fi->database,
- fi->table);
+ if (!same_table_flag->answer) {
+ if (where_opt->answer)
+ ret =
+ db_copy_table_where(driver_opt->answer, database_opt->answer,
+ table_opt->answer, fi->driver,
+ fi->database, fi->table,
+ where_opt->answer);
+ else
+ ret =
+ db_copy_table(driver_opt->answer, database_opt->answer,
+ table_opt->answer, fi->driver, fi->database,
+ fi->table);
- if (ret == DB_FAILED) {
- G_warning(_("Unable to copy table"));
+ if (ret == DB_FAILED) {
+ G_warning(_("Unable to copy table"));
+ }
+ else {
+ Vect_map_add_dblink(&Map, 1, NULL, fi->table, keycol_opt->answer,
+ fi->database, fi->driver);
+ }
}
else {
- Vect_map_add_dblink(&Map, 1, NULL, fi->table, keycol_opt->answer,
- fi->database, fi->driver);
+ Vect_map_add_dblink(&Map, 1, NULL, table_opt->answer,
+ keycol_opt->answer, database_opt->answer,
+ driver_opt->answer);
}
Vect_build(&Map);
More information about the grass-commit
mailing list