[GRASS-SVN] r52793 - grass/trunk/vector/v.transform
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Aug 20 10:58:40 PDT 2012
Author: mmetz
Date: 2012-08-20 10:58:38 -0700 (Mon, 20 Aug 2012)
New Revision: 52793
Modified:
grass/trunk/vector/v.transform/local_proto.h
grass/trunk/vector/v.transform/main.c
grass/trunk/vector/v.transform/trans_digit.c
Log:
v.transform close database shutdown driver when done; remove ugly table hack
Modified: grass/trunk/vector/v.transform/local_proto.h
===================================================================
--- grass/trunk/vector/v.transform/local_proto.h 2012-08-20 17:57:58 UTC (rev 52792)
+++ grass/trunk/vector/v.transform/local_proto.h 2012-08-20 17:58:38 UTC (rev 52793)
@@ -1,4 +1,4 @@
/* trans_digit.c */
int transform_digit_file(struct Map_info *, struct Map_info *,
- double, int, double *, char *, char **, int);
+ double, int, double *, char **, int);
Modified: grass/trunk/vector/v.transform/main.c
===================================================================
--- grass/trunk/vector/v.transform/main.c 2012-08-20 17:57:58 UTC (rev 52792)
+++ grass/trunk/vector/v.transform/main.c 2012-08-20 17:58:38 UTC (rev 52793)
@@ -46,7 +46,7 @@
struct GModule *module;
struct Option *vold, *vnew, *xshift, *yshift, *zshift,
- *xscale, *yscale, *zscale, *zrot, *columns, *table, *field;
+ *xscale, *yscale, *zscale, *zrot, *columns, *field_opt;
struct Flag *tozero_flag, *print_mat_flag, *swap_flag, *no_topo;
char mon[4], date[40], buf[1000];
@@ -62,6 +62,7 @@
int idx, out3d;
char **tokens;
char *columns_name[7]; /* xshift, yshift, zshift, xscale, yscale, zscale, zrot */
+ int field;
G_gisinit(argv[0]);
@@ -92,8 +93,8 @@
vold = G_define_standard_option(G_OPT_V_INPUT);
- field = G_define_standard_option(G_OPT_V_FIELD_ALL);
- field->guisection = _("Custom");
+ field_opt = G_define_standard_option(G_OPT_V_FIELD_ALL);
+ field_opt->guisection = _("Custom");
vnew = G_define_standard_option(G_OPT_V_OUTPUT);
@@ -161,11 +162,6 @@
zrot->answer = "0.0";
zrot->guisection = _("Custom");
- table = G_define_standard_option(G_OPT_DB_TABLE);
- table->description =
- _("Name of table containing transformation parameters");
- table->guisection = _("Custom");
-
columns = G_define_standard_option(G_OPT_DB_COLUMNS);
columns->label =
_("Name of attribute column(s) used as transformation parameters");
@@ -181,17 +177,16 @@
Vect_check_input_output_name(vold->answer, vnew->answer, G_FATAL_EXIT);
- out3d = WITHOUT_Z;
+ /* open input vector */
+ Vect_open_old2(&Old, vold->answer, "", field_opt->answer);
- if (!table->answer && columns->answer) {
- G_fatal_error(_("Table name is not defined. Please use '%s' parameter."),
- table->key);
+ field = Vect_get_field_number(&Old, field_opt->answer);
+ if (field < 1 && columns->answer) {
+ G_fatal_error(_("Columns require a valid layer. Please use '%s' parameter."),
+ field_opt->key);
}
- if (table->answer && strcmp(vnew->answer, table->answer) == 0) {
- G_fatal_error(_("Name of table and name for output vector map must be different. "
- "Otherwise the table is overwritten."));
- }
+ out3d = Vect_is_3d(&Old);
/* tokenize columns names */
for (i = 0; i <= IDX_ZROT; i++) {
@@ -241,15 +236,12 @@
trans_params[IDX_ZSCALE] = atof(zscale->answer);
trans_params[IDX_ZROT] = atof(zrot->answer);
- /* open vector maps */
- Vect_open_old2(&Old, vold->answer, "", field->answer);
-
/* should output be 3D ?
* note that z-scale and ztozero have no effect with input 2D */
- if (Vect_is_3d(&Old) || trans_params[IDX_ZSHIFT] != 0. ||
- columns_name[IDX_ZSHIFT])
+ if (trans_params[IDX_ZSHIFT] != 0. || columns_name[IDX_ZSHIFT])
out3d = WITH_Z;
+ /* open output vector */
Vect_open_new(&New, vnew->answer, out3d);
/* copy and set header */
@@ -284,7 +276,7 @@
G_important_message(_("Tranforming features..."));
transform_digit_file(&Old, &New,
ztozero, swap_flag->answer, trans_params,
- table->answer, columns_name, Vect_get_field_number(&Old, field->answer));
+ columns_name, field);
G_important_message(_("Copying attributes..."));
if (Vect_copy_tables(&Old, &New, 0))
Modified: grass/trunk/vector/v.transform/trans_digit.c
===================================================================
--- grass/trunk/vector/v.transform/trans_digit.c 2012-08-20 17:57:58 UTC (rev 52792)
+++ grass/trunk/vector/v.transform/trans_digit.c 2012-08-20 17:58:38 UTC (rev 52793)
@@ -9,9 +9,9 @@
int transform_digit_file(struct Map_info *Old, struct Map_info *New,
double ztozero, int swap, double *trans_params_def,
- char *table, char **columns, int field)
+ char **columns, int field)
{
- int i, type, cat, line;
+ int i, type, cat, line, ret;
int verbose, format;
unsigned int j;
double *trans_params;
@@ -30,8 +30,9 @@
Points = Vect_new_line_struct();
Cats = Vect_new_cats_struct();
- if (table) {
- fi = Vect_default_field_info(Old, 1, NULL, GV_1TABLE);
+ driver = NULL;
+ if (field > 0) {
+ fi = Vect_get_field(Old, field);
driver = db_start_driver_open_database(fi->driver, fi->database);
if (!driver)
@@ -46,16 +47,21 @@
}
line = 0;
+ ret = 1;
format = G_info_format();
verbose = G_verbose() > G_verbose_min();
while (TRUE) {
type = Vect_read_next_line(Old, Points, Cats);
- if (type == -1) /* error */
- return 0;
+ if (type == -1) { /* error */
+ ret = 0;
+ break;
+ }
- if (type == -2) /* EOF */
- return 1;
+ if (type == -2) { /* EOF */
+ ret = 1;
+ break;
+ }
if (field != -1 && !Vect_cat_get(Cats, field, NULL))
continue;
@@ -76,7 +82,7 @@
}
/* get transformation parameters */
- if (table) {
+ if (field > 0) {
Vect_cat_get(Cats, field, &cat); /* get first category */
if (cat > -1) {
for (j = 0; j <= IDX_ZROT; j++) {
@@ -84,7 +90,7 @@
trans_params[j] = trans_params_def[j];
continue;
}
- ctype = db_column_Ctype(driver, table, columns[j]);
+ ctype = db_column_Ctype(driver, fi->table, columns[j]);
switch (ctype) {
case DB_C_TYPE_INT:
case DB_C_TYPE_DOUBLE:
@@ -92,19 +98,19 @@
break;
case -1:
G_fatal_error(_("Missing column <%s> in table <%s>"),
- columns[j], table);
+ columns[j], fi->table);
default:
G_fatal_error(_("Unsupported column type of <%s>"),
columns[j]);
}
if (db_select_value
- (driver, table, fi->key, cat, columns[j], &val) != 1
+ (driver, fi->table, fi->key, cat, columns[j], &val) != 1
|| db_test_value_isnull(&val)) {
trans_params[j] = trans_params_def[j];
G_warning(_("Unable to select value for category %d from table <%s>, column <%s>. "
"For category %d using default transformation parameter %.3f."),
- cat, table, columns[j], cat,
+ cat, fi->table, columns[j], cat,
trans_params[j]);
}
else {
@@ -159,4 +165,6 @@
db_close_database_shutdown_driver(driver);
G_free((void *)trans_params);
}
+
+ return ret;
}
More information about the grass-commit
mailing list