[GRASS-SVN] r45827 - grass-addons/display/d.barb
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Apr 3 01:03:30 EDT 2011
Author: hamish
Date: 2011-04-02 22:03:30 -0700 (Sat, 02 Apr 2011)
New Revision: 45827
Modified:
grass-addons/display/d.barb/draw.c
grass-addons/display/d.barb/local_proto.h
grass-addons/display/d.barb/main.c
grass-addons/display/d.barb/points.c
Log:
add support for u,v vector maps
Modified: grass-addons/display/d.barb/draw.c
===================================================================
--- grass-addons/display/d.barb/draw.c 2011-04-03 04:11:46 UTC (rev 45826)
+++ grass-addons/display/d.barb/draw.c 2011-04-03 05:03:30 UTC (rev 45827)
@@ -6,10 +6,7 @@
#include <grass/glocale.h>
#include "local_proto.h"
-#define RpD ((2 * M_PI) / 360.) /* radians/degree */
-#define D2R(d) (double)(d * RpD) /* degrees->radians */
-
/* draw a single barb at the given map coordinates */
void draw_barb(double easting, double northing, double velocity,
double compass_deg, int color, double scale, int style)
Modified: grass-addons/display/d.barb/local_proto.h
===================================================================
--- grass-addons/display/d.barb/local_proto.h 2011-04-03 04:11:46 UTC (rev 45826)
+++ grass-addons/display/d.barb/local_proto.h 2011-04-03 05:03:30 UTC (rev 45827)
@@ -10,6 +10,10 @@
#define TYPE_BARB 1
#define TYPE_ARROW 2
+#define RpD ((2 * M_PI) / 360.) /* radians/degree */
+#define D2R(d) (double)(d * RpD) /* degrees->radians */
+#define R2D(d) (double)(d / RpD) /* radians->degrees */
+
/* grid.c */
void do_barb_grid(char *, char *, int, int, int, double, int, int);
Modified: grass-addons/display/d.barb/main.c
===================================================================
--- grass-addons/display/d.barb/main.c 2011-04-03 04:11:46 UTC (rev 45826)
+++ grass-addons/display/d.barb/main.c 2011-04-03 05:03:30 UTC (rev 45827)
@@ -173,7 +173,7 @@
if (u_opt->answer && v_opt->answer) {
is_component = TRUE;
- strncpy(dir_u_map, u_opt->answer, sizeof(dir_u_map) - 1); /* FIXME: not well null terminated on overflow */
+ strncpy(dir_u_map, u_opt->answer, sizeof(dir_u_map) - 1);
strncpy(mag_v_map, v_opt->answer, sizeof(mag_v_map) - 1);
}
else if (dir_opt->answer && magn_opt->answer) {
@@ -181,6 +181,8 @@
strncpy(dir_u_map, dir_opt->answer, sizeof(dir_u_map) - 1);
strncpy(mag_v_map, magn_opt->answer, sizeof(mag_v_map) - 1);
}
+ dir_u_map[sizeof(dir_u_map) - 1] = '\0'; /* strncpy() doesn't null-terminate on overflow */
+ mag_v_map[sizeof(mag_v_map) - 1] = '\0';
if (vinput_opt->answer)
is_vector = TRUE;
@@ -231,8 +233,6 @@
color = D_parse_color(color_opt->answer, 0);
- /*////// do it ////////// */
-
// is D_setup() actually needed?
D_setup(0);
Modified: grass-addons/display/d.barb/points.c
===================================================================
--- grass-addons/display/d.barb/points.c 2011-04-03 04:11:46 UTC (rev 45826)
+++ grass-addons/display/d.barb/points.c 2011-04-03 05:03:30 UTC (rev 45827)
@@ -67,28 +67,11 @@
}
}
- // to figure out:
- // also pass u,v columns and calc dir,mag prior to filling dirn,magn arrays
-
-
- /* somehow check, load attributes see d.vect */
-
-
- /*
- if(is_component) {
- read u attrib;
- read v attrib;
- dir= ...calc;
- velo= ...calc;
- }
- else {
- read dir attrib;
- read velo attrib;
- }
-
- if (aspect_type == TYPE_COMPASS)
- dir = 90 - dir;
+ /* todone?
+ if (aspect_type == TYPE_COMPASS)
+ dir = 90 - dir;
*/
+
peak = max_magnitude(magn, num_pts);
G_debug(0, " peak = %.2f", peak);
if (style == TYPE_BARB && peak > 150)
@@ -167,6 +150,7 @@
dbDriver *driver = NULL;
dbCatValArray cvarr_dir_u, cvarr_mag_v;
dbCatVal *cv_dir_u = NULL, *cv_mag_v = NULL;
+ double theta, r;
G_debug(0, "fill_arrays()");
@@ -248,9 +232,9 @@
G_debug(5, " Xs[%d] = %.2f Ys[%d] = %.2f cat = %d", i, Xs[i],
i, Ys[i], Cats->cat[0]);
+
/* Read rotation from db */
- if (db_CatValArray_get_value(&cvarr_dir_u, Cats->cat[0], &cv_dir_u) !=
- DB_OK)
+ if (db_CatValArray_get_value(&cvarr_dir_u, Cats->cat[0], &cv_dir_u) != DB_OK)
Dirs[i] = 0.0 / 0.0; /* NaN */
else
Dirs[i] = cvarr_dir_u.ctype == DB_C_TYPE_INT ?
@@ -265,10 +249,20 @@
else
Mags[i] = cvarr_mag_v.ctype == DB_C_TYPE_INT ?
(double)cv_mag_v->val.i : cv_mag_v->val.d;
+ if (!is_uv) {
+ if (Mags[i] < 0) /* magnitude is scalar and can only be positive */
+ Mags[i] = 0;
+ }
+ }
- if (Mags[i] < 0) /* magnitude is scalar and can only be positive */
- Mags[i] = 0;
+ if(is_uv) {
+ /* now that we have the data loaded, cycle back and process it */
+ theta = R2D(atan2(Mags[i], Dirs[i]));
+ r = sqrt(Dirs[i]*Dirs[i] + Mags[i]*Mags[i]);
+ Dirs[i] = theta;
+ Mags[i] = r;
}
+
G_debug(5, " Dirs[%d] = %.2f Mags[%d] = %.2f", i, Dirs[i],
i, Mags[i]);
i++;
More information about the grass-commit
mailing list