[GRASS-SVN] r70050 - grass/trunk/vector/v.transform

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Dec 10 12:28:33 PST 2016


Author: wenzeslaus
Date: 2016-12-10 12:28:33 -0800 (Sat, 10 Dec 2016)
New Revision: 70050

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: swap flags also for the z coordinate, optionally swap at the end [news]

Modified: grass/trunk/vector/v.transform/local_proto.h
===================================================================
--- grass/trunk/vector/v.transform/local_proto.h	2016-12-09 18:15:57 UTC (rev 70049)
+++ grass/trunk/vector/v.transform/local_proto.h	2016-12-10 20:28:33 UTC (rev 70050)
@@ -1,4 +1,4 @@
 
 /* trans_digit.c */
 int transform_digit_file(struct Map_info *, struct Map_info *,
-			 double, int, double *, char **, int);
+                         double, int, int, int, int, double *, char **, int);

Modified: grass/trunk/vector/v.transform/main.c
===================================================================
--- grass/trunk/vector/v.transform/main.c	2016-12-09 18:15:57 UTC (rev 70049)
+++ grass/trunk/vector/v.transform/main.c	2016-12-10 20:28:33 UTC (rev 70050)
@@ -46,7 +46,8 @@
 
     struct Option *vold, *vnew, *xshift, *yshift, *zshift,
 	*xscale, *yscale, *zscale, *zrot, *columns, *field_opt;
-    struct Flag *tozero_flag, *swap_flag, *no_topo;
+    struct Flag *tozero_flag, *no_topo;
+    struct Flag *swap_flag, *swap_xz_flag, *swap_yz_flag, *swap_after_flag;
 
     char mon[4], date[40], buf[1000];
     struct Map_info Old, New;
@@ -82,7 +83,22 @@
     swap_flag->key = 'w';
     swap_flag->description =
 	_("Swap coordinates x, y and then apply other parameters");
-    
+
+    swap_xz_flag = G_define_flag();
+    swap_xz_flag->key = 'x';
+    swap_xz_flag->description =
+        _("Swap coordinates x, z and then apply other parameters");
+
+    swap_yz_flag = G_define_flag();
+    swap_yz_flag->key = 'y';
+    swap_yz_flag->description =
+        _("Swap coordinates y, z and then apply other parameters");
+
+    swap_after_flag = G_define_flag();
+    swap_after_flag->key = 'a';
+    swap_after_flag->description =
+        _("Swap coordinates after the other transformations");
+
     no_topo = G_define_flag();
     no_topo->key = 'b';
     no_topo->description = _("Do not build topology");
@@ -165,6 +181,9 @@
 	_("Format: parameter:column, e.g. xshift:xs,yshift:ys,zrot:zr");
     columns->guisection = _("Custom");
 
+    /* we don't define order of swapping, so only one can be used safely */
+    G_option_exclusive(swap_flag, swap_xz_flag, swap_yz_flag, NULL);
+
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
@@ -275,9 +294,10 @@
 
     /* do the transformation */
     G_important_message(_("Transforming features..."));
-    transform_digit_file(&Old, &New,
-			 ztozero, swap_flag->answer, trans_params,
-			 columns_name, field);
+    transform_digit_file(&Old, &New, ztozero, swap_flag->answer,
+                         swap_xz_flag->answer, swap_yz_flag->answer,
+                         swap_after_flag->answer, trans_params, 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	2016-12-09 18:15:57 UTC (rev 70049)
+++ grass/trunk/vector/v.transform/trans_digit.c	2016-12-10 20:28:33 UTC (rev 70050)
@@ -8,14 +8,15 @@
 #define PI M_PI
 
 int transform_digit_file(struct Map_info *Old, struct Map_info *New,
-			 double ztozero, int swap, double *trans_params_def,
-			 char **columns, int field)
+                         double ztozero, int swap_xy, int swap_xz,
+                         int swap_yz, int swap_after,
+                         double *trans_params_def, char **columns, int field)
 {
     int i, type, cat, line, ret;
     int verbose, format;
     unsigned int j;
     double *trans_params;
-    double ang, x, y;
+    double ang, x, y, tmp;
     static struct line_pnts *Points;
     static struct line_cats *Cats;
 
@@ -73,15 +74,29 @@
 	    else
 		fprintf(stderr, "%11d\b\b\b\b\b\b\b\b\b\b\b", line);
 	}
-	
-	if (swap) {
-	    for (i = 0; i < Points->n_points; i++) {
-		x = Points->x[i];
-		Points->x[i] = Points->y[i];
-		Points->y[i] = x;
-	    }
-	} 
-	
+
+        if (swap_xy && !swap_after) {
+            for (i = 0; i < Points->n_points; i++) {
+                x = Points->x[i];
+                Points->x[i] = Points->y[i];
+                Points->y[i] = x;
+            }
+        }
+        if (swap_xz && !swap_after) {
+            for (i = 0; i < Points->n_points; i++) {
+                tmp = Points->z[i];
+                Points->z[i] = Points->x[i];
+                Points->x[i] = tmp;
+            }
+        }
+        if (swap_yz && !swap_after) {
+            for (i = 0; i < Points->n_points; i++) {
+                tmp = Points->z[i];
+                Points->z[i] = Points->y[i];
+                Points->y[i] = tmp;
+            }
+        }
+
 	/* get transformation parameters */
 	if (field > 0) {
 	    Vect_cat_get(Cats, field, &cat);	/* get first category */
@@ -153,6 +168,24 @@
 	    Points->z[i] =
 		((Points->z[i] + ztozero) * trans_params[IDX_ZSCALE]) +
 		trans_params[IDX_ZSHIFT];
+
+            if (swap_after) {
+                if (swap_xy) {
+                    tmp = Points->x[i];
+                    Points->x[i] = Points->y[i];
+                    Points->y[i] = tmp;
+                }
+                if (swap_xz) {
+                    tmp = Points->z[i];
+                    Points->z[i] = Points->x[i];
+                    Points->x[i] = tmp;
+                }
+                if (swap_yz) {
+                    tmp = Points->z[i];
+                    Points->z[i] = Points->y[i];
+                    Points->y[i] = tmp;
+                }
+            }
 	}
 
 	Vect_write_line(New, type, Points, Cats);



More information about the grass-commit mailing list