On Thursday 28 February 2008, Philipp Steigenberger wrote:
> Hi
> I want to work with r.plane and r.lake to get simulate floodings in DTMs.
>
> In the section of interest there is a river which runs from about SSW to
> NNE. For r.plane I need the
> azimuth. Is there a tool in GRASS which tells me the angle between two
> points I mark on the map like I can measure in between two points with
> d.measure?
>

Well of course I had to go and try this out.

attached is a patch (against todays SVN) to optionally print the bearing 
between clicks.

Dylan


-- 
Dylan Beaudette
Soil Resource Laboratory
http://casoilresource.lawr.ucdavis.edu/
University of California at Davis
530.754.7341
Index: display/d.measure/local_proto.h
===================================================================
--- display/d.measure/local_proto.h	(revision 30395)
+++ display/d.measure/local_proto.h	(working copy)
@@ -1,7 +1,8 @@
 /* draw_line.c */
 int draw_line(int, int, int, int, int, int);
 /* msurements.c */
-int measurements(int, int, int, int, int);
+int measurements(int, int, int, int, int, int);
 int print_en(double, double, int);
 int print_length(double, int, int);
+int print_bearing_deg (double, double, double, double, int);
 int add_point(double **, double **, int *, int *, double, double);
Index: display/d.measure/msurements.c
===================================================================
--- display/d.measure/msurements.c	(revision 30395)
+++ display/d.measure/msurements.c	(working copy)
@@ -2,11 +2,14 @@
 #include <grass/display.h>
 #include <grass/raster.h>
 #include "local_proto.h"
+#include <math.h>
+#include <unistd.h>
 
+#define PI  M_PI
 
 FILE *output;
 
-int measurements(int color1,int color2, int s_flag, int m_flag, int k_flag)
+int measurements(int color1,int color2, int s_flag, int m_flag, int k_flag, int b_flag)
 {
     double *x, *y;
     int npoints, nalloc;
@@ -89,7 +92,14 @@
                 draw_line(screen_x,screen_y,cur_screen_x,cur_screen_y,color1,color2)  ;
 		add_point (&x, &y, &npoints, &nalloc, ux, uy);
                 length += G_distance(cur_ux, cur_uy, ux, uy) ;
+                
+                if(b_flag)
+					print_bearing_deg(cur_ux, ux, cur_uy, uy, s_flag);
+					
                 print_length(length, s_flag, k_flag);
+                
+                
+                
                 cur_screen_x = screen_x ;
                 cur_screen_y = screen_y ;
                 cur_ux = ux ;
@@ -163,6 +173,19 @@
     return 0;
 }
 
+int print_bearing_deg (double cur_ux, double ux, double cur_uy, double uy, int s_flag)
+{
+    /* Use stderr for TCLTK-Output */
+    if( s_flag )
+      output = stderr;
+    else
+      output = stdout;
+	
+    fprintf (output,"Bearing:   %3.2f degrees\n", atan2(uy - cur_uy, ux - cur_ux) * 180/PI) ;
+
+    return 0;
+}
+
 int add_point (double **x, double **y,
     int *npoints, int *nalloc, double ux, double uy)
 {
Index: display/d.measure/main.c
===================================================================
--- display/d.measure/main.c	(revision 30395)
+++ display/d.measure/main.c	(working copy)
@@ -20,6 +20,7 @@
  *
  *****************************************************************************/
 #include <stdlib.h>
+
 #include <grass/gis.h>
 #include <grass/display.h>
 #include <grass/raster.h>
@@ -38,8 +39,9 @@
 	   struct Flag *s;
 	   struct Flag *m;
 	   struct Flag *k;
+	   struct Flag *b;
 	} parm;
-	int color1, color2, s_flag, m_flag, k_flag;
+	int color1, color2, s_flag, m_flag, k_flag, b_flag;
 
 	/* Initialize the GIS calls */
 	G_gisinit(argv[0]) ;
@@ -79,6 +81,10 @@
 	parm.k->key = 'k';
 	parm.k->description = _("Output in kilometers as well");
 	
+	parm.b = G_define_flag();
+	parm.b->key = 'b';
+	parm.b->description = _("Print bearing between points");
+	
 	if (argc > 1 && G_parser(argc,argv))
 	    exit(EXIT_FAILURE);
 
@@ -96,8 +102,9 @@
 	s_flag = parm.s->answer;
 	m_flag = parm.m->answer;
 	k_flag = parm.k->answer;
+	b_flag = parm.b->answer;
 
-	measurements(color1, color2, s_flag, m_flag, k_flag ) ;
+	measurements(color1, color2, s_flag, m_flag, k_flag, b_flag ) ;
 
 	R_close_driver();
 
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

Reply via email to