Hi,

I have posted some minor cosmetic / printing patches in the past to the Gforge 
site, however it looks like they were either overlooked- or not deemed worth 
implementing.

The patch in mind enabled printing of the transformation matrix, as computed 
by v.transform, when prompted by the user. I have tried to add this 
functionality with a minimal impact on module design- and followed several of 
Glynn's suggested coding practices. The patches are attached to this message. 

If this is too specialized for v.transform I will continue to maintain my 
local copies. What do people think?

Cheers,

Dylan


-- 
Dylan Beaudette
Soils and Biogeochemistry Graduate Group
University of California at Davis
530.754.7341
? lib/vector/transform/OBJ.i686-pc-linux-gnu
Index: lib/vector/transform/transform.c
===================================================================
RCS file: /home/grass/grassrepository/grass6/lib/vector/transform/transform.c,v
retrieving revision 1.2
diff -u -r1.2 transform.c
--- lib/vector/transform/transform.c	9 Feb 2006 03:08:58 -0000	1.2
+++ lib/vector/transform/transform.c	19 Sep 2007 19:04:54 -0000
@@ -60,7 +60,7 @@
     double residual[]        residual error for each point
     double *rms;             overall root mean square error
 ****************************************************************/
-
+#include <stdio.h>
 #include <math.h>
 #include <grass/libtrans.h>
 
@@ -68,6 +68,8 @@
 static double A0,A1,A2,A3,A4,A5;
 static double B0,B1,B2,B3,B4,B5;
 
+
+
 static int resid(
     double *,double *,double *,double *,int *,int,double *,double *,int);
 
@@ -144,6 +146,7 @@
     B4 = bbr[1];
     B5 = bbr[2];
 
+
 /* the inverse equation */
 
     x = B2 * B4 - B1 * B5 ;
@@ -180,6 +183,23 @@
 
     return 0;
 }
+
+
+/*
+return the transformation matrix in a convinient format
+*/
+int print_transform_matrix()
+	{
+	fprintf(stdout, "\nTransformation Matrix\n");
+	fprintf(stdout, "| xoff a b |\n");
+	fprintf(stdout, "| yoff d e |\n");
+	fprintf(stdout, "-------------------------------------\n");
+	fprintf(stdout, "%f %f %f \n", -B3, B2, -B5);
+	fprintf(stdout, "%f %f %f \n", -B0, -B1, B4);
+	fprintf(stdout, "-------------------------------------\n");
+	return 1 ;
+	}
+
 
 /**************************************************************
 These routines are internal to this source code
? vector/v.transform/OBJ.i686-pc-linux-gnu
Index: vector/v.transform/description.html
===================================================================
RCS file: /home/grass/grassrepository/grass6/vector/v.transform/description.html,v
retrieving revision 1.13
diff -u -r1.13 description.html
--- vector/v.transform/description.html	7 Sep 2007 14:10:36 -0000	1.13
+++ vector/v.transform/description.html	19 Sep 2007 19:07:48 -0000
@@ -37,6 +37,15 @@
 parameters based on their category number. If the parameter cannot be
 fetched from the table, default value is used instead.<p>
 
+<h3>Affine Transformation Matrix</h3>
+The affine transformation matrix can optionally be printed with the '-m' flag. The format of the matrix is:
+<div class="code" style="width:30%;"><pre>
+| x_offset a b |
+| y_offset d e |
+</pre></div>
+
+This format can be used in the <a href="http://postgis.refractions.net/docs/ch06.html#id2904406";>Affine() function of PostGIS</a> [Affine(geom, a, b, d, e, xoff, yoff)], or directly compared to the output of a similar operation performed in R.
+
 <h2>EXAMPLE</h2>
 
 <h3>DXF/DWG drawings</h3>
Index: vector/v.transform/main.c
===================================================================
RCS file: /home/grass/grassrepository/grass6/vector/v.transform/main.c,v
retrieving revision 1.34
diff -u -r1.34 main.c
--- vector/v.transform/main.c	7 Sep 2007 14:10:36 -0000	1.34
+++ vector/v.transform/main.c	19 Sep 2007 19:07:49 -0000
@@ -44,9 +44,10 @@
     struct file_info  Current, Trans, Coord;
 
     struct GModule *module;
+
     struct Option *old, *new, *pointsfile, *xshift, *yshift, *zshift,
       *xscale, *yscale, *zscale, *zrot, *columns, *table, *field;
-    struct Flag *quiet_flag, *tozero_flag, *shift_flag;
+    struct Flag *quiet_flag, *tozero_flag, *shift_flag, *print_mat_flag;;
 
     char   *mapset, mon[4], date[40], buf[1000];
     struct Map_info Old, New;
@@ -77,7 +78,12 @@
     tozero_flag = G_define_flag();
     tozero_flag->key		= 't';
     tozero_flag->description = _("Shift all z values to bottom=0"); 
-
+	
+	
+	print_mat_flag = G_define_flag();
+    print_mat_flag->key		= 'm';
+    print_mat_flag->description = _("Print the transformation matrix to stdout"); 
+	
     /* remove in GRASS7 */
     shift_flag = G_define_flag();
     shift_flag->key		= 's';
@@ -321,15 +327,23 @@
 
     if (!quiet_flag->answer) {
 	Vect_get_map_box (&New, &box );
-	G_message ( _("New vector map <%s> boundary coordinates:"), new->answer);
+	G_message ( _("\nNew vector map <%s> boundary coordinates:"), new->answer);
 	G_message ( _(" N: %-10.3f    S: %-10.3f"), box.N, box.S);
 	G_message ( _(" E: %-10.3f    W: %-10.3f"), box.E, box.W);
 	G_message ( _(" B: %6.3f    T: %6.3f"), box.B, box.T);
+    
+    /*
+	print the transformation matrix if requested
+	*/
+	if (print_mat_flag->answer)
+		print_transform_matrix();
+    
     }
 
     Vect_close (&New);
 
     G_done_msg (" ");
+
 
     exit(EXIT_SUCCESS) ;
 }
_______________________________________________
grass-dev mailing list
[email protected]
http://grass.itc.it/mailman/listinfo/grass-dev

Reply via email to