[GRASS-SVN] r52783 - grass/branches/develbranch_6/vector/v.transform

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Aug 20 08:32:50 PDT 2012


Author: mmetz
Date: 2012-08-20 08:32:49 -0700 (Mon, 20 Aug 2012)
New Revision: 52783

Modified:
   grass/branches/develbranch_6/vector/v.transform/main.c
   grass/branches/develbranch_6/vector/v.transform/trans_digit.c
Log:
v.transform fix for #1615

Modified: grass/branches/develbranch_6/vector/v.transform/main.c
===================================================================
--- grass/branches/develbranch_6/vector/v.transform/main.c	2012-08-20 15:32:38 UTC (rev 52782)
+++ grass/branches/develbranch_6/vector/v.transform/main.c	2012-08-20 15:32:49 UTC (rev 52783)
@@ -58,11 +58,11 @@
     BOUND_BOX box;
 
     double ztozero;
-    double trans_params[7];	// xshift, ..., xscale, ..., zrot
+    double trans_params[7];	/* xshift, ..., xscale, ..., zrot */
 
     /* columns */
     unsigned int i;
-    int idx;
+    int idx, out3d;
     char **tokens;
     char *columns_name[7];	/* xshift, yshift, zshift, xscale, yscale, zscale, zrot */
 
@@ -206,6 +206,8 @@
     G_strcpy(Trans.name, vnew->answer);
 
     Vect_check_input_output_name(vold->answer, vnew->answer, GV_FATAL_EXIT);
+    
+    out3d = WITHOUT_Z;
 
     /* please remove in GRASS7 */
     if (shift_flag->answer)
@@ -243,52 +245,6 @@
 			  Coord.name);
     }
 
-    /* open vector maps */
-    if ((mapset = G_find_vector2(vold->answer, "")) == NULL)
-	G_fatal_error(_("Vector map <%s> not found"), vold->answer);
-
-    Vect_open_old(&Old, vold->answer, mapset);
-    
-    Vect_open_new(&New, vnew->answer, Vect_is_3d(&Old) || tozero_flag->answer ||
-		  strcmp(zshift->answer, "0.0") || strcmp(zscale->answer, "1.0") ||
-		  strcmp(zrot->answer, "0.0") ? WITH_Z : WITHOUT_Z);
-    
-    /* copy and set header */
-    Vect_copy_head_data(&Old, &New);
-
-    Vect_hist_copy(&Old, &New);
-    Vect_hist_command(&New);
-
-    sprintf(date, "%s", G_date());
-    sscanf(date, "%*s%s%d%*s%d", mon, &day, &yr);
-    sprintf(date, "%s %d %d", mon, day, yr);
-    Vect_set_date(&New, date);
-
-    Vect_set_person(&New, G_whoami());
-
-    sprintf(buf, "transformed from %s", vold->answer);
-    Vect_set_map_name(&New, buf);
-
-    Vect_set_scale(&New, 1);
-    Vect_set_zone(&New, 0);
-    Vect_set_thresh(&New, 0.0);
-
-    /* points file */
-    if (Coord.name[0]) {
-	create_transform_from_file(&Coord, quiet_flag->answer);
-
-	if (Coord.name[0] != '\0')
-	    fclose(Coord.fp);
-    }
-
-    Vect_get_map_box(&Old, &box);
-
-    /* z to zero */
-    if (tozero_flag->answer)
-	ztozero = 0 - box.B;
-    else
-	ztozero = 0;
-
     /* tokenize columns names */
     for (i = 0; i <= IDX_ZROT; i++) {
 	columns_name[i] = NULL;
@@ -337,6 +293,57 @@
     trans_params[IDX_ZSCALE] = atof(zscale->answer);
     trans_params[IDX_ZROT] = atof(zrot->answer);
 
+    /* open vector maps */
+    if ((mapset = G_find_vector2(vold->answer, "")) == NULL)
+	G_fatal_error(_("Vector map <%s> not found"), vold->answer);
+
+    Vect_open_old(&Old, vold->answer, mapset);
+    
+    /* 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])
+	out3d = WITH_Z;
+
+    Vect_open_new(&New, vnew->answer, out3d);
+    
+    /* copy and set header */
+    Vect_copy_head_data(&Old, &New);
+
+    Vect_hist_copy(&Old, &New);
+    Vect_hist_command(&New);
+
+    sprintf(date, "%s", G_date());
+    sscanf(date, "%*s%s%d%*s%d", mon, &day, &yr);
+    sprintf(date, "%s %d %d", mon, day, yr);
+    Vect_set_date(&New, date);
+
+    Vect_set_person(&New, G_whoami());
+
+    sprintf(buf, "transformed from %s", vold->answer);
+    Vect_set_map_name(&New, buf);
+
+    Vect_set_scale(&New, 1);
+    Vect_set_zone(&New, 0);
+    Vect_set_thresh(&New, 0.0);
+
+    /* points file */
+    if (Coord.name[0]) {
+	create_transform_from_file(&Coord, quiet_flag->answer);
+
+	if (Coord.name[0] != '\0')
+	    fclose(Coord.fp);
+    }
+
+    Vect_get_map_box(&Old, &box);
+
+    /* z to zero */
+    if (tozero_flag->answer)
+	ztozero = 0 - box.B;
+    else
+	ztozero = 0;
+
+    /* do the transformation */
     transform_digit_file(&Old, &New, Coord.name[0] ? 1 : 0,
 			 ztozero, swap_flag->answer, trans_params,
 			 table->answer, columns_name, atoi(field->answer));

Modified: grass/branches/develbranch_6/vector/v.transform/trans_digit.c
===================================================================
--- grass/branches/develbranch_6/vector/v.transform/trans_digit.c	2012-08-20 15:32:38 UTC (rev 52782)
+++ grass/branches/develbranch_6/vector/v.transform/trans_digit.c	2012-08-20 15:32:49 UTC (rev 52783)
@@ -32,7 +32,7 @@
 		     int shift_file, double ztozero, int swap, double *trans_params_def,
 		     char *table, char **columns, int field)
 {
-    int i, type, cat;
+    int i, type, cat, ret;
     unsigned int j;
     double *trans_params;
     double ang, x, y;
@@ -65,14 +65,19 @@
 	ang = PI * trans_params[IDX_ZROT] / 180;
     }
 
+    ret = 1;
     while (1) {
 	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 (swap) {
 	    for (i = 0; i < Points->n_points; i++) {



More information about the grass-commit mailing list