[GRASS-SVN] r53554 - grass/branches/releasebranch_6_4/vector/v.transform
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Oct 25 08:22:28 PDT 2012
Author: mmetz
Date: 2012-10-25 08:22:27 -0700 (Thu, 25 Oct 2012)
New Revision: 53554
Modified:
grass/branches/releasebranch_6_4/vector/v.transform/main.c
grass/branches/releasebranch_6_4/vector/v.transform/trans_digit.c
Log:
v.transform: fix memory issues
Modified: grass/branches/releasebranch_6_4/vector/v.transform/main.c
===================================================================
--- grass/branches/releasebranch_6_4/vector/v.transform/main.c 2012-10-25 15:22:23 UTC (rev 53553)
+++ grass/branches/releasebranch_6_4/vector/v.transform/main.c 2012-10-25 15:22:27 UTC (rev 53554)
@@ -54,6 +54,7 @@
char *mapset, mon[4], date[40], buf[1000];
struct Map_info Old, New;
+ int ifield;
int day, yr;
BOUND_BOX box;
@@ -74,6 +75,7 @@
_("Performs an affine transformation (shift, scale and rotate, "
"or GPCs) on vector map.");
+ /* remove in GRASS7 */
quiet_flag = G_define_flag();
quiet_flag->key = 'q';
quiet_flag->description =
@@ -89,7 +91,6 @@
print_mat_flag->description =
_("Print the transformation matrix to stdout");
- /* remove in GRASS7 */
shift_flag = G_define_flag();
shift_flag->key = 's';
shift_flag->description =
@@ -100,6 +101,7 @@
vold = G_define_standard_option(G_OPT_V_INPUT);
field = G_define_standard_option(G_OPT_V_FIELD);
+ field->answer = "-1";
vnew = G_define_standard_option(G_OPT_V_OUTPUT);
@@ -202,29 +204,42 @@
Vect_check_input_output_name(vold->answer, vnew->answer, GV_FATAL_EXIT);
out3d = WITHOUT_Z;
+
+ ifield = atoi(field->answer);
- /* please remove in GRASS7 */
if (shift_flag->answer)
G_warning(_("The '%c' flag is deprecated and will be removed in future. "
"Transformation parameters are used automatically when no pointsfile is given."),
shift_flag->key);
+ /* please remove in GRASS7 */
if (quiet_flag->answer) {
G_warning(_("The '%c' flag is deprecated and will be removed in future. "
"Please use '--quiet' instead."), quiet_flag->key);
G_putenv("GRASS_VERBOSE", "0");
}
- if (!table->answer && columns->answer) {
- G_fatal_error(_("Table name is not defined. Please use '%s' parameter."),
- table->key);
+ /* if a table is specified, require columns and layer */
+ /* if columns are specified, but no table, require layer > 0 and use
+ * the table attached to that layer */
+ if (table->answer && !columns->answer) {
+ G_fatal_error(_("Column names are not defined. Please use '%s' parameter."),
+ columns->key);
}
+ if ((columns->answer || table->answer) && ifield < 1) {
+ G_fatal_error(_("Please specify a valid layer with '%s' parameter."),
+ field->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."));
}
+ if (!columns->answer && !table->answer)
+ ifield = -1;
+
if (pointsfile->answer != NULL && !shift_flag->answer) {
G_strcpy(Coord.name, pointsfile->answer);
}
@@ -340,7 +355,7 @@
/* do the transformation */
transform_digit_file(&Old, &New, Coord.name[0] ? 1 : 0,
ztozero, trans_params,
- table->answer, columns_name, atoi(field->answer));
+ table->answer, columns_name, ifield);
if (Vect_copy_tables(&Old, &New, 0))
G_warning(_("Failed to copy attribute table to output map"));
Modified: grass/branches/releasebranch_6_4/vector/v.transform/trans_digit.c
===================================================================
--- grass/branches/releasebranch_6_4/vector/v.transform/trans_digit.c 2012-10-25 15:22:23 UTC (rev 53553)
+++ grass/branches/releasebranch_6_4/vector/v.transform/trans_digit.c 2012-10-25 15:22:27 UTC (rev 53554)
@@ -50,19 +50,27 @@
Points = Vect_new_line_struct();
Cats = Vect_new_cats_struct();
- if (table) {
- fi = Vect_default_field_info(Old, 1, NULL, GV_1TABLE);
+ if (table || field > 0) {
+ if (table) {
+ fi = Vect_default_field_info(Old, 1, NULL, GV_1TABLE);
+ fi->table = table;
+ }
+ else
+ fi = Vect_get_field(Old, field);
+
driver = db_start_driver_open_database(fi->driver, fi->database);
if (!driver)
G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
fi->database, fi->driver);
- trans_params = (double *)G_calloc(IDX_ZROT, sizeof(double));
+ trans_params = (double *)G_calloc(IDX_ZROT + 1, sizeof(double));
}
else {
trans_params = trans_params_def;
ang = PI * trans_params[IDX_ZROT] / 180;
+ fi = NULL;
+ driver = NULL;
}
ret = 1;
@@ -80,7 +88,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++) {
@@ -88,7 +96,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:
@@ -96,19 +104,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 {
More information about the grass-commit
mailing list