On Thursday 28 February 2008, Dylan Beaudette wrote:
> 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
And of course here is an updated patch which computes bearing from 0 (math
style North = 90 deg) or from 90 (compass style North = 0 deg).
--
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);
int print_en(double, double, int);
int print_length(double, int, int);
+int print_bearing_deg (double, double, double, double, int, 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, int c_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, c_flag);
+
print_length(length, s_flag, k_flag);
+
+
+
cur_screen_x = screen_x ;
cur_screen_y = screen_y ;
cur_ux = ux ;
@@ -163,6 +173,42 @@
return 0;
}
+/**
+\brief compute the bearing in degrees from click to next click.
+
+\note North is at 90 degrees by default, it can be shifted to 0 degrees (like a compass) with the '-c' flag
+*/
+int print_bearing_deg (double cur_ux, double ux, double cur_uy, double uy, int s_flag, int c_flag)
+{
+ double bearing_deg ;
+ double dx, dy;
+
+ /* Use stderr for TCLTK-Output */
+ if( s_flag )
+ output = stderr;
+ else
+ output = stdout;
+
+ dx = ux - cur_ux ;
+ dy = uy - cur_uy ;
+
+ /* put north at 0 deg by subtracting PI/2 */
+ if( c_flag)
+ {
+ bearing_deg = (atan2(dy, dx) - PI/2) * 180/PI ;
+ if(bearing_deg < 0)
+ bearing_deg = 360 + bearing_deg;
+ }
+
+ /* north is at 90 deg */
+ else
+ bearing_deg = atan2(dy, dx) * 180/PI ;
+
+ fprintf (output,"Bearing: %3.2f degrees\n", bearing_deg) ;
+
+ 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,10 @@
struct Flag *s;
struct Flag *m;
struct Flag *k;
+ struct Flag *b;
+ struct Flag *c;
} parm;
- int color1, color2, s_flag, m_flag, k_flag;
+ int color1, color2, s_flag, m_flag, k_flag, b_flag, c_flag;
/* Initialize the GIS calls */
G_gisinit(argv[0]) ;
@@ -79,6 +82,14 @@
parm.k->key = 'k';
parm.k->description = _("Output in kilometers as well");
+ parm.b = G_define_flag();
+ parm.b->key = 'b';
+ parm.b->description = _("Compute bearing between points (north is 90 degrees)");
+
+ parm.c = G_define_flag();
+ parm.c->key = 'c';
+ parm.c->description = _("Use compass-style bearing (north is 0 degrees)");
+
if (argc > 1 && G_parser(argc,argv))
exit(EXIT_FAILURE);
@@ -96,8 +107,10 @@
s_flag = parm.s->answer;
m_flag = parm.m->answer;
k_flag = parm.k->answer;
+ b_flag = parm.b->answer;
+ c_flag = parm.c->answer;
- measurements(color1, color2, s_flag, m_flag, k_flag ) ;
+ measurements(color1, color2, s_flag, m_flag, k_flag, b_flag, c_flag ) ;
R_close_driver();
_______________________________________________
grass-user mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/grass-user