On Monday 04 June 2007 01:14, Hamish wrote:
> Dylan:
> > > good call, that was definitely bad style on my part. Instead of
> > > debug, a flag might be a good option?
>
> Glynn:
> > Within the module, you can use G_verbose_message() for messages which
> > should only printed when --verbose is used. Or you could add a
> > specific flag.
>
> Output intended to be parsable should use fprintf(stdout, "..." ,,,);
This looks like the best approach: however, I am getting a compile error
on 'stdout' not being defined... ideas?
> G_*_message() and G_debug() will output to stderr and are more for
> messages than outputing data.
>
>
> A flag for output is a nice idea, whichever stdout or stderr you feel is
> more appropriate.
>
I have implemented it as a flag. Patch is attached
If this looks ok, I can re-submit it to the grass tracker
thanks!
--
Dylan Beaudette
Soils and Biogeochemistry Graduate Group
University of California at Davis
530.754.7341
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 4 Jun 2007 16:50:14 -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
Index: vector/v.transform/description.html
===================================================================
RCS file: /home/grass/grassrepository/grass6/vector/v.transform/description.html,v
retrieving revision 1.8
diff -u -r1.8 description.html
--- vector/v.transform/description.html 11 Jan 2006 10:26:57 -0000 1.8
+++ vector/v.transform/description.html 4 Jun 2007 16:50:17 -0000
@@ -28,6 +28,14 @@
The ground control points may be also (ir)regularly distributed
and can be more than four points.
+<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>
Index: vector/v.transform/main.c
===================================================================
RCS file: /home/grass/grassrepository/grass6/vector/v.transform/main.c,v
retrieving revision 1.30
diff -u -r1.30 main.c
--- vector/v.transform/main.c 26 Mar 2007 15:30:40 -0000 1.30
+++ vector/v.transform/main.c 4 Jun 2007 16:50:17 -0000
@@ -41,7 +41,7 @@
struct file_info Current, Trans, Coord ;
struct GModule *module;
struct Option *old, *new, *pointsfile, *xshift, *yshift, *zshift, *xscale, *yscale, *zscale, *zrot;
- 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;
int day, yr;
@@ -63,7 +63,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';
@@ -228,15 +233,22 @@
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