Ticket #76: d.measure_bearing.patch
| File d.measure_bearing.patch, 5.6 KB (added by , 16 years ago) |
|---|
-
d.measure/local_proto.h
1 1 /* draw_line.c */ 2 2 int draw_line(int, int, int, int, int, int); 3 3 /* msurements.c */ 4 int measurements(int, int, int, int, int );4 int measurements(int, int, int, int, int, int, int); 5 5 int print_en(double, double, int); 6 6 int print_length(double, int, int); 7 int print_bearing_deg (double, double, double, double, int, int); 7 8 int add_point(double **, double **, int *, int *, double, double); -
d.measure/msurements.c
2 2 #include <grass/display.h> 3 3 #include <grass/raster.h> 4 4 #include "local_proto.h" 5 #include <math.h> 6 #include <unistd.h> 5 7 8 #define PI M_PI 6 9 7 10 FILE *output; 8 11 9 int measurements(int color1,int color2, int s_flag, int m_flag, int k_flag )12 int measurements(int color1,int color2, int s_flag, int m_flag, int k_flag, int b_flag, int c_flag) 10 13 { 11 14 double *x, *y; 12 15 int npoints, nalloc; … … 89 92 draw_line(screen_x,screen_y,cur_screen_x,cur_screen_y,color1,color2) ; 90 93 add_point (&x, &y, &npoints, &nalloc, ux, uy); 91 94 length += G_distance(cur_ux, cur_uy, ux, uy) ; 95 96 if(b_flag) 97 print_bearing_deg(cur_ux, ux, cur_uy, uy, s_flag, c_flag); 98 92 99 print_length(length, s_flag, k_flag); 100 101 102 93 103 cur_screen_x = screen_x ; 94 104 cur_screen_y = screen_y ; 95 105 cur_ux = ux ; … … 163 173 return 0; 164 174 } 165 175 176 /** 177 \brief compute the bearing in degrees from click to next click. 178 179 \note North is at 90 degrees by default 180 \note north can be shifted to 0 degrees, and increment degrees increase counter-clockwise (like a compass) with the '-c' flag 181 */ 182 int print_bearing_deg (double cur_ux, double ux, double cur_uy, double uy, int s_flag, int c_flag) 183 { 184 double bearing_deg ; 185 double dx, dy; 186 187 /* Use stderr for TCLTK-Output */ 188 if( s_flag ) 189 output = stderr; 190 else 191 output = stdout; 192 193 dx = ux - cur_ux ; 194 dy = uy - cur_uy ; 195 196 /* format output to compass-like bearings: 197 198 put north at 0 deg by subtracting PI/2 199 set to counter-clockwise like a compass by setting 'dx' to '-dx' */ 200 if( c_flag) 201 { 202 bearing_deg = (atan2(dy, -dx) - PI/2) * 180/PI ; 203 if(bearing_deg < 0) 204 bearing_deg = 360 + bearing_deg; 205 } 206 207 /* standard math-style 208 north is at 90 deg */ 209 else 210 bearing_deg = atan2(dy, dx) * 180/PI ; 211 212 fprintf (output,"Bearing: %3.2f degrees\n", bearing_deg) ; 213 214 return 0; 215 } 216 166 217 int add_point (double **x, double **y, 167 218 int *npoints, int *nalloc, double ux, double uy) 168 219 { -
d.measure/main.c
20 20 * 21 21 *****************************************************************************/ 22 22 #include <stdlib.h> 23 23 24 #include <grass/gis.h> 24 25 #include <grass/display.h> 25 26 #include <grass/raster.h> … … 38 39 struct Flag *s; 39 40 struct Flag *m; 40 41 struct Flag *k; 42 struct Flag *b; 43 struct Flag *c; 41 44 } parm; 42 int color1, color2, s_flag, m_flag, k_flag ;45 int color1, color2, s_flag, m_flag, k_flag, b_flag, c_flag; 43 46 44 47 /* Initialize the GIS calls */ 45 48 G_gisinit(argv[0]) ; … … 79 82 parm.k->key = 'k'; 80 83 parm.k->description = _("Output in kilometers as well"); 81 84 85 parm.b = G_define_flag(); 86 parm.b->key = 'b'; 87 parm.b->description = _("Compute bearing between points, relative to x-axis (north is 90 degrees)"); 88 89 parm.c = G_define_flag(); 90 parm.c->key = 'c'; 91 parm.c->description = _("Use compass-style bearing (north is 0 degrees, increases CCW)"); 92 82 93 if (argc > 1 && G_parser(argc,argv)) 83 94 exit(EXIT_FAILURE); 84 95 … … 91 102 if (D_set_cur_wind(frame)) 92 103 G_fatal_error(_("Current frame not available")); 93 104 105 /* test for bearing calculation request in a LL location */ 106 if (parm.b->answer && G_projection() == PROJECTION_LL) 107 G_fatal_error(_("bearing calculation is not available for LL projection")); 108 109 /* issue an error if the c flag is issued without the b flag */ 110 if (parm.c->answer && !parm.b->answer) 111 G_fatal_error(_("the -c flag can only be used in conjunction with the -b flag")); 112 94 113 color1 = D_translate_color (parm.c1->answer); 95 114 color2 = D_translate_color (parm.c2->answer); 96 115 s_flag = parm.s->answer; 97 116 m_flag = parm.m->answer; 98 117 k_flag = parm.k->answer; 118 b_flag = parm.b->answer; 119 c_flag = parm.c->answer; 99 120 100 measurements(color1, color2, s_flag, m_flag, k_flag ) ;121 measurements(color1, color2, s_flag, m_flag, k_flag, b_flag, c_flag ) ; 101 122 102 123 R_close_driver(); 103 124 -
d.measure/description.html
35 35 If the user draws an area within another area, the combined 36 36 area of both regions will be output. 37 37 38 <EM>Bearing Calculations</EM> 39 Calcuation of bearings can be done in two ways: 40 <ol> 41 <li>math-style: angles are computed relative to the positive x-axis, with the starting point at the origin (north at 90 degrees)</li> 42 <li>compass-style: angles are computed relative to the positive y-axis, with the starting point at the origin (north at 0 degrees)</li> 43 </ol> 44 38 45 <H2>TODO</H2> 39 46 40 47 Output lengths in the same units as those of the current LOCATION as
