[GRASS-SVN] r38508 - grass/branches/develbranch_6/display/d.vect
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jul 23 04:13:53 EDT 2009
Author: hamish
Date: 2009-07-23 04:13:53 -0400 (Thu, 23 Jul 2009)
New Revision: 38508
Modified:
grass/branches/develbranch_6/display/d.vect/local_proto.h
grass/branches/develbranch_6/display/d.vect/main.c
grass/branches/develbranch_6/display/d.vect/plot1.c
Log:
new options for dynamic symbol size and rotation (trac #600)
Modified: grass/branches/develbranch_6/display/d.vect/local_proto.h
===================================================================
--- grass/branches/develbranch_6/display/d.vect/local_proto.h 2009-07-23 08:07:43 UTC (rev 38507)
+++ grass/branches/develbranch_6/display/d.vect/local_proto.h 2009-07-23 08:13:53 UTC (rev 38508)
@@ -1,11 +1,11 @@
-#include <grass/symbol.h>
#include <grass/colors.h>
FILE *open_vect(char *, char *);
int close_vect(FILE *);
int plot1(struct Map_info *, int, int, struct cat_list *,
- const struct color_rgb *, const struct color_rgb *, int, SYMBOL *,
- int, int, int, int, char *, int, char *, double, int, char *);
+ const struct color_rgb *, const struct color_rgb *, int, char *,
+ int, char *, char *, int, int, int, char *, int, char *, double,
+ int, char *);
int label(struct Map_info *, int, int, struct cat_list *, LATTR *, int);
int topo(struct Map_info *, int, int, LATTR *);
int dir(struct Map_info *, int, struct cat_list *, int);
Modified: grass/branches/develbranch_6/display/d.vect/main.c
===================================================================
--- grass/branches/develbranch_6/display/d.vect/main.c 2009-07-23 08:07:43 UTC (rev 38507)
+++ grass/branches/develbranch_6/display/d.vect/main.c 2009-07-23 08:13:53 UTC (rev 38508)
@@ -22,7 +22,6 @@
#include <grass/display.h>
#include <grass/Vect.h>
#include <grass/colors.h>
-#include <grass/symbol.h>
#include <grass/dbmi.h>
#include <grass/glocale.h>
#include "plot.h"
@@ -94,7 +93,7 @@
struct Option *map_opt;
struct Option *color_opt, *fcolor_opt, *rgbcol_opt, *zcol_opt;
struct Option *type_opt, *display_opt;
- struct Option *icon_opt, *size_opt;
+ struct Option *icon_opt, *size_opt, *sizecolumn_opt, *rotcolumn_opt;
struct Option *where_opt;
struct Option *field_opt, *cat_opt, *lfield_opt;
struct Option *lcolor_opt, *bgcolor_opt, *bcolor_opt;
@@ -115,7 +114,6 @@
struct Cell_head window;
BOUND_BOX box;
double overlap;
- SYMBOL *Symb;
/* Initialize the GIS calls */
G_gisinit(argv[0]);
@@ -231,6 +229,20 @@
size_opt->guisection = _("Symbols");
size_opt->description = _("Symbol size");
+ sizecolumn_opt = G_define_standard_option(G_OPT_COLUMN);
+ sizecolumn_opt->key = "size_column";
+ sizecolumn_opt->guisection = _("Symbols");
+ sizecolumn_opt->description =
+ _("Name of numeric column containing symbol size");
+
+ rotcolumn_opt = G_define_standard_option(G_OPT_COLUMN);
+ rotcolumn_opt->key = "rot_column";
+ rotcolumn_opt->guisection = _("Symbols");
+ rotcolumn_opt->label =
+ _("Name of numeric column containing symbol rotation angle");
+ rotcolumn_opt->description =
+ _("Measured in degrees CCW from east");
+
/* Labels */
lfield_opt = G_define_standard_option(G_OPT_V_FIELD);
lfield_opt->key = "llayer";
@@ -467,11 +479,6 @@
}
size = atoi(size_opt->answer);
- Symb = S_read(icon_opt->answer);
- if (Symb == NULL)
- G_warning(_("Unable to read symbol, unable todisplay points"));
- else
- S_stroke(Symb, size, 0.0, 0);
/* Make sure map is available */
mapset = G_find_vector2(map_name, "");
@@ -686,7 +693,8 @@
else {
stat = plot1(&Map, type, area, Clist,
has_color ? &color : NULL,
- has_fcolor ? &fcolor : NULL, chcat, Symb, size,
+ has_fcolor ? &fcolor : NULL, chcat, icon_opt->answer,
+ size, sizecolumn_opt->answer, rotcolumn_opt->answer,
(int)id_flag->answer, table_acolors_flag->answer,
cats_acolors_flag->answer, rgbcol_opt->answer,
default_width, wcolumn_opt->answer, width_scale,
Modified: grass/branches/develbranch_6/display/d.vect/plot1.c
===================================================================
--- grass/branches/develbranch_6/display/d.vect/plot1.c 2009-07-23 08:07:43 UTC (rev 38507)
+++ grass/branches/develbranch_6/display/d.vect/plot1.c 2009-07-23 08:13:53 UTC (rev 38508)
@@ -128,10 +128,11 @@
/* *************************************************************** */
int plot1(struct Map_info *Map, int type, int area, struct cat_list *Clist,
const struct color_rgb *color, const struct color_rgb *fcolor,
- int chcat, SYMBOL * Symb, int size, int id_flag,
- int table_colors_flag, int cats_color_flag, char *rgb_column,
- int default_width, char *width_column, double width_scale,
- int z_color_flag, char *style)
+ int chcat, char *symbol_name, int size, char *size_column,
+ char *rot_column, int id_flag, int table_colors_flag,
+ int cats_color_flag, char *rgb_column, int default_width,
+ char *width_column, double width_scale, int z_color_flag,
+ char *style)
{
int i, ltype, nlines = 0, line, cat = -1;
double *x, *y;
@@ -142,9 +143,9 @@
struct field_info *fi = NULL;
dbDriver *driver = NULL;
- dbCatValArray cvarr_rgb, cvarr_width;
- dbCatVal *cv_rgb = NULL, *cv_width = NULL;
- int nrec_rgb = 0, nrec_width = 0;
+ dbCatValArray cvarr_rgb, cvarr_width, cvarr_size, cvarr_rot;
+ dbCatVal *cv_rgb = NULL, *cv_width = NULL, *cv_size = NULL, *cv_rot = NULL;
+ int nrec_rgb = 0, nrec_width = 0, nrec_size = 0, nrec_rot = 0;
int nerror_rgb;
int open_db;
@@ -154,9 +155,13 @@
RGBA_Color *line_color, *fill_color, *primary_color;
unsigned char which;
int width;
+ SYMBOL *Symb;
+ double var_size, rotation;
+ var_size = (double)size;
+ rotation = 0.0;
nerror_rgb = 0;
-
+
line_color = G_malloc(sizeof(RGBA_Color));
fill_color = G_malloc(sizeof(RGBA_Color));
primary_color = G_malloc(sizeof(RGBA_Color));
@@ -189,7 +194,7 @@
PPoints = Vect_new_line_struct();
Cats = Vect_new_cats_struct();
- open_db = table_colors_flag || width_column;
+ open_db = table_colors_flag || width_column || size_column || rot_column;
if (open_db) {
fi = Vect_get_field(Map, (Clist->field > 0 ? Clist->field : 1));
@@ -247,17 +252,17 @@
if (cvarr_width.ctype != DB_C_TYPE_INT &&
cvarr_width.ctype != DB_C_TYPE_DOUBLE)
- G_fatal_error(_("Line width column (%s) not a number."),
+ G_fatal_error(_("Line width column (%s) is not numeric."),
width_column);
if (nrec_width < 0)
G_fatal_error(_("Cannot select data (%s) from table"),
width_column);
- G_debug(2, "\n%d records selected from table", nrec_width);
+ G_debug(2, " %d records selected from table", nrec_width);
for (i = 0; i < cvarr_width.n_values; i++) {
- G_debug(4, "cat = %d %s = %d", cvarr_width.value[i].cat,
+ G_debug(4, "(width) cat = %d %s = %d", cvarr_width.value[i].cat,
width_column,
(cvarr_width.ctype ==
DB_C_TYPE_INT ? cvarr_width.value[i].val.
@@ -265,6 +270,76 @@
}
}
+ if (size_column) {
+ if (*size_column == '\0')
+ G_fatal_error(_("Symbol size column not specified."));
+
+ db_CatValArray_init(&cvarr_size);
+
+ nrec_size = db_select_CatValArray(driver, fi->table, fi->key,
+ size_column, NULL, &cvarr_size);
+
+ G_debug(3, "nrec_size (%s) = %d", size_column, nrec_size);
+
+ if (cvarr_size.ctype != DB_C_TYPE_INT &&
+ cvarr_size.ctype != DB_C_TYPE_DOUBLE)
+ G_fatal_error(_("Symbol size column (%s) is not numeric."),
+ size_column);
+
+ if (nrec_size < 0)
+ G_fatal_error(_("Cannot select data (%s) from table"),
+ size_column);
+
+ G_debug(2, " %d records selected from table", nrec_size);
+
+ for (i = 0; i < cvarr_size.n_values; i++) {
+ G_debug(4, "(size) cat = %d %s = %d", cvarr_size.value[i].cat,
+ size_column,
+ (cvarr_size.ctype ==
+ DB_C_TYPE_INT ? cvarr_size.value[i].val.
+ i : (int)cvarr_size.value[i].val.d));
+ }
+ }
+
+ if (rot_column) {
+ if (*rot_column == '\0')
+ G_fatal_error(_("Symbol rotation column not specified."));
+
+ db_CatValArray_init(&cvarr_rot);
+
+ nrec_rot = db_select_CatValArray(driver, fi->table, fi->key,
+ rot_column, NULL, &cvarr_rot);
+
+ G_debug(3, "nrec_rot (%s) = %d", rot_column, nrec_rot);
+
+ if (cvarr_rot.ctype != DB_C_TYPE_INT &&
+ cvarr_rot.ctype != DB_C_TYPE_DOUBLE)
+ G_fatal_error(_("Symbol rotation column (%s) is not numeric."),
+ rot_column);
+
+ if (nrec_rot < 0)
+ G_fatal_error(_("Cannot select data (%s) from table"),
+ rot_column);
+
+ G_debug(2, " %d records selected from table", nrec_rot);
+
+ for (i = 0; i < cvarr_rot.n_values; i++) {
+ G_debug(4, "(rot) cat = %d %s = %d", cvarr_rot.value[i].cat,
+ rot_column,
+ (cvarr_rot.ctype ==
+ DB_C_TYPE_INT ? cvarr_rot.value[i].val.
+ i : (int)cvarr_rot.value[i].val.d));
+ }
+ }
+
+ if( !(nrec_size || nrec_rot) ) {
+ Symb = S_read(symbol_name);
+ if (Symb == NULL)
+ G_warning(_("Unable to read symbol, unable to display points"));
+ else
+ S_stroke(Symb, size, 0.0, 0);
+ }
+
if (open_db)
db_close_database_shutdown_driver(driver);
@@ -444,12 +519,11 @@
(Clist->field > 0 ? Clist->field :
(Cats->n_cats >
0 ? Cats->field[0] : 1)), &cat);
-
+
if (cat >= 0) {
G_debug(3, "display element %d, cat %d", line, cat);
/* Read line width from db for current area # */
-
if (db_CatValArray_get_value(&cvarr_width, cat, &cv_width) !=
DB_OK) {
width = default_width;
@@ -466,20 +540,20 @@
width = default_width;
}
}
- } /* end if cat */
+ } /* end if cat */
else {
width = default_width;
}
D_line_width(width);
- } /* end if nrec_width */
+ } /* end if nrec_width */
/* enough of the prep work, lets start plotting stuff */
x = Points->x;
y = Points->y;
- if ((ltype & GV_POINTS) && Symb != NULL) {
+ if ((ltype & GV_POINTS) && (Symb != NULL || (nrec_size || nrec_rot)) ) {
if (!(color || fcolor || custom_rgb))
continue;
@@ -492,6 +566,81 @@
y0 > D_get_d_south() || y0 < D_get_d_north())
continue;
+ /* dynamic symbol size */
+ if (nrec_size) {
+ /* only first category */
+ Vect_cat_get(Cats,
+ (Clist->field > 0 ? Clist->field :
+ (Cats->n_cats > 0 ?
+ Cats->field[0] : 1)), &cat);
+
+ if (cat >= 0) {
+ G_debug(3, "display element %d, cat %d", line, cat);
+
+ /* Read symbol size from db for current symbol # */
+ if (db_CatValArray_get_value(&cvarr_size, cat, &cv_size) !=
+ DB_OK) {
+ var_size = (double)size;
+ }
+ else {
+ var_size =
+ (cvarr_size.ctype == DB_C_TYPE_INT ?
+ (double)cv_size->val.i : cv_size->val.d);
+
+ if (var_size < 0.0) {
+ G_warning(_("Error in symbol size column (%s), element %d "
+ "with cat %d: symbol size [%f]"),
+ size_column, line, cat, var_size);
+ var_size = (double)size;
+ }
+ }
+ } /* end if cat */
+ else {
+ var_size = (double)size;
+ }
+ } /* end if nrec_size */
+
+ /* dynamic symbol rotation */
+ if (nrec_rot) {
+ /* only first category */
+ Vect_cat_get(Cats,
+ (Clist->field > 0 ? Clist->field :
+ (Cats->n_cats > 0 ?
+ Cats->field[0] : 1)), &cat);
+
+ if (cat >= 0) {
+ G_debug(3, "display element %d, cat %d", line, cat);
+
+ /* Read symbol rotation from db for current symbol # */
+ if (db_CatValArray_get_value(&cvarr_rot, cat, &cv_rot) !=
+ DB_OK) {
+ rotation = 0.0;
+ }
+ else {
+ rotation =
+ (cvarr_rot.ctype == DB_C_TYPE_INT ?
+ (double)cv_rot->val.i : cv_rot->val.d);
+ }
+ } /* end if cat */
+ else {
+ rotation = 0.0;
+ }
+ } /* end if nrec_rot */
+
+ if(nrec_size || nrec_rot) {
+ G_debug(3, ". dynamic symbol: cat=%d size=%d rotation=%.2f",
+ cat, (int)(var_size + 0.5), rotation);
+
+ /* symbol stroking is cumulative, so we need to reread it each time */
+ if(Symb) /* unclean free() on first iteration if variables are not init'd to NULL? */
+ G_free(Symb);
+ Symb = S_read(symbol_name);
+ if (Symb == NULL)
+ G_warning(_("Unable to read symbol, unable to display points"));
+ else
+ S_stroke(Symb, (int)(var_size + 0.5), rotation, 0);
+ }
+
/* use random or RGB column color if given, otherwise reset */
/* centroids always use default color to stand out from underlying area */
if (custom_rgb && (ltype != GV_CENTROID)) {
@@ -503,7 +652,9 @@
else
D_symbol(Symb, x0, y0, line_color, fill_color);
-
+ /* reset to defaults */
+ var_size = (double)size;
+ rotation = 0.0;
}
else if (color || custom_rgb || (z_color_flag && Vect_is_3d(Map))) {
if (!table_colors_flag && !cats_color_flag && !z_color_flag)
More information about the grass-commit
mailing list