[GRASS-SVN] r59055 - grass/trunk/display/d.vect

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Feb 15 08:26:21 PST 2014


Author: martinl
Date: 2014-02-15 08:26:21 -0800 (Sat, 15 Feb 2014)
New Revision: 59055

Modified:
   grass/trunk/display/d.vect/area.c
   grass/trunk/display/d.vect/d.vect.html
   grass/trunk/display/d.vect/lines.c
   grass/trunk/display/d.vect/local_proto.h
   grass/trunk/display/d.vect/main.c
   grass/trunk/display/d.vect/shape.c
Log:
d.vect: simplify usage (colorize features), `-a` flag removed


Modified: grass/trunk/display/d.vect/area.c
===================================================================
--- grass/trunk/display/d.vect/area.c	2014-02-15 01:17:01 UTC (rev 59054)
+++ grass/trunk/display/d.vect/area.c	2014-02-15 16:26:21 UTC (rev 59055)
@@ -232,6 +232,10 @@
 	}
     }
 
+    if ((colors || cvarr_rgb) && get_num_color_rules_skipped() > 0)
+        G_warning(_("%d invalid color rules for areas skipped"), 
+                  get_num_color_rules_skipped());
+
     Vect_destroy_line_struct(Points);
     Vect_destroy_line_struct(APoints);
     for (i = 0; i < n_ipoints_alloc; i++) {

Modified: grass/trunk/display/d.vect/d.vect.html
===================================================================
--- grass/trunk/display/d.vect/d.vect.html	2014-02-15 01:17:01 UTC (rev 59054)
+++ grass/trunk/display/d.vect/d.vect.html	2014-02-15 16:26:21 UTC (rev 59055)
@@ -19,11 +19,10 @@
 <p>In order to display attributes in the map, <b>attribute_column</b> must
 be specified.
 
-<p>Colors may be specified
-by <em><a href="v.colors.html">v.colors</a></em> as a color table or
-in an attribute table column named 'GRASSRGB' (which is
-a <tt>varchar(11)</tt> column containing <tt>RRR:GGG:BBB</tt> values),
-see the flag <b>-a</b>.
+<p>Feature colors may be specified
+by <em><a href="v.colors.html">v.colors</a></em> in a form of color
+table or in an attribute table column containing <tt>RRR:GGG:BBB</tt>
+values.
 
 <p>A table for a vector map might look like this:
 

Modified: grass/trunk/display/d.vect/lines.c
===================================================================
--- grass/trunk/display/d.vect/lines.c	2014-02-15 01:17:01 UTC (rev 59054)
+++ grass/trunk/display/d.vect/lines.c	2014-02-15 16:26:21 UTC (rev 59055)
@@ -165,6 +165,10 @@
 		  &n_faces);
     }
     
+    if ((colors || cvarr_rgb) && get_num_color_rules_skipped() > 0)
+        G_warning(_("%d invalid color rules for lines skipped"), 
+                  get_num_color_rules_skipped());
+
     if (n_points > 0) 
 	G_verbose_message(_("%d points plotted"), n_points);
     if (n_lines > 0) 

Modified: grass/trunk/display/d.vect/local_proto.h
===================================================================
--- grass/trunk/display/d.vect/local_proto.h	2014-02-15 01:17:01 UTC (rev 59054)
+++ grass/trunk/display/d.vect/local_proto.h	2014-02-15 16:26:21 UTC (rev 59055)
@@ -38,7 +38,7 @@
 int display_shape(struct Map_info *, int, struct cat_list *, const struct Cell_head *, 
 		  const struct color_rgb *, const struct color_rgb *, int,
 		  const char *, double, const char *, int, const char *, /* lines only */
-		  int, int, int, char *,
+		  int, int, char *,
 		  int, char *, double,
 		  int, char *);
 int get_table_color(int, int, struct Colors *, dbCatValArray *,
@@ -46,6 +46,7 @@
 int get_cat_color(int, const struct line_cats *, const struct cat_list *,
 		  int *, int *, int *);
 double get_property(int, int, dbCatValArray *, double, double);
+int get_num_color_rules_skipped();
 
 /* opt.c */
 int option_to_display(const struct Option *);

Modified: grass/trunk/display/d.vect/main.c
===================================================================
--- grass/trunk/display/d.vect/main.c	2014-02-15 01:17:01 UTC (rev 59054)
+++ grass/trunk/display/d.vect/main.c	2014-02-15 16:26:21 UTC (rev 59055)
@@ -5,7 +5,7 @@
  * AUTHOR(S):    CERL, Radim Blazek, others
  *               Updated to GRASS7 by Martin Landa <landa.martin gmail.com>
  * PURPOSE:      Display the vector map in map display
- * COPYRIGHT:    (C) 2004-2009, 2011 by the GRASS Development Team
+ * COPYRIGHT:    (C) 2004-2014 by the GRASS Development Team
  *
  *               This program is free software under the GNU General
  *               Public License (>=v2). Read the file COPYING that
@@ -52,7 +52,7 @@
     struct Option *lsize_opt, *font_opt, *enc_opt, *xref_opt, *yref_opt;
     struct Option *attrcol_opt, *maxreg_opt, *minreg_opt;
     struct Option *width_opt, *wcolumn_opt, *wscale_opt;
-    struct Flag *id_flag, *table_acolors_flag, *cats_acolors_flag,
+    struct Flag *id_flag, *cats_acolors_flag,
 	*zcol_flag, *sqrt_flag;
     char *desc;
     
@@ -136,8 +136,8 @@
     rgbcol_opt = G_define_standard_option(G_OPT_DB_COLUMN);
     rgbcol_opt->key = "rgb_column";
     rgbcol_opt->guisection = _("Colors");
-    rgbcol_opt->description = _("Name of color definition column (for use with -a flag)");
-    rgbcol_opt->answer = "GRASSRGB";
+    rgbcol_opt->label = _("Colorize features according color definition column");
+    rgbcol_opt->description = _("Color definition in R:G:B form");
     
     zcol_opt = G_define_standard_option(G_OPT_M_COLR);
     zcol_opt->key = "zcolor";
@@ -296,12 +296,6 @@
 	  "when map is displayed");
 
     /* Colors */
-    table_acolors_flag = G_define_flag();
-    table_acolors_flag->key = 'a';
-    table_acolors_flag->guisection = _("Colors");
-    table_acolors_flag->description =
-	_("Get colors from attribute table (see 'rgb_column' option)");
-
     cats_acolors_flag = G_define_flag();
     cats_acolors_flag->key = 'c';
     cats_acolors_flag->guisection = _("Colors");
@@ -364,10 +358,11 @@
 	default_width = 0;
     width_scale = atof(wscale_opt->answer);
 
-    if (table_acolors_flag->answer && cats_acolors_flag->answer) {
-	cats_acolors_flag->answer = '\0';
-	G_warning(_("The '-c' and '-a' flags cannot be used together, "
-		    "the '-c' flag will be ignored!"));
+    if (cats_acolors_flag->answer && rgbcol_opt->answer) {
+	G_warning(_("The -%c flag and <%s> option cannot be used together, "
+		    "the -%c flag will be ignored!"), 
+                  cats_acolors_flag->key, rgbcol_opt->key, cats_acolors_flag->key);
+        cats_acolors_flag->answer = FALSE;
     }
 
     color = G_standard_color_rgb(WHITE);
@@ -442,11 +437,11 @@
 	    stat += display_shape(&Map, type, Clist, &window,
 				  has_color ? &color : NULL, has_fcolor ? &fcolor : NULL, chcat,
 				  icon_opt->answer, size, sizecolumn_opt->answer,
-				  sqrt_flag->answer ? 1 : 0, rotcolumn_opt->answer,
-				  id_flag->answer ? 1 : 0, table_acolors_flag->answer ? 1 : 0,
-				  cats_acolors_flag->answer ? 1 : 0, rgbcol_opt->answer,
+				  sqrt_flag->answer ? TRUE : FALSE, rotcolumn_opt->answer,
+				  id_flag->answer ? TRUE : FALSE, 
+				  cats_acolors_flag->answer ? TRUE : FALSE, rgbcol_opt->answer,
 				  default_width,  wcolumn_opt->answer, width_scale,
-				  zcol_flag->answer ? 1 : 0, zcol_opt->answer);
+				  zcol_flag->answer ? TRUE : FALSE, zcol_opt->answer);
 	    
 	    if (wcolumn_opt->answer)
 		D_line_width(default_width);

Modified: grass/trunk/display/d.vect/shape.c
===================================================================
--- grass/trunk/display/d.vect/shape.c	2014-02-15 01:17:01 UTC (rev 59054)
+++ grass/trunk/display/d.vect/shape.c	2014-02-15 16:26:21 UTC (rev 59055)
@@ -5,6 +5,8 @@
 
 #include "local_proto.h"
 
+static int ncolor_rules_skipped = 0;
+
 static void error_handler(void *p)
 {
     dbDriver *driver = (dbDriver *) p;
@@ -12,10 +14,15 @@
     db_close_database_shutdown_driver(driver);
 }
 
+int get_num_color_rules_skipped()
+{
+    return ncolor_rules_skipped;
+}
+
 int display_shape(struct Map_info *Map, int type, struct cat_list *Clist, const struct Cell_head *window, 
 		  const struct color_rgb *bcolor, const struct color_rgb *fcolor, int chcat,
 		  const char *icon, double size, const char *size_column, int sqrt_flag, const char *rot_column, /* lines only */
-		  int id_flag, int table_colors_flag, int cats_colors_flag, char *rgb_column,
+		  int id_flag, int cats_colors_flag, char *rgb_column,
 		  int default_width, char *width_column, double width_scale,
 		  int z_color_flag, char *z_style)
 {
@@ -30,7 +37,7 @@
     stat = 0;
     nrec_rgb = nrec_width = nrec_size = nrec_rot = 0;
     
-    open_db = table_colors_flag || width_column || size_column || rot_column;
+    open_db = rgb_column || width_column || size_column || rot_column;
     if (open_db) {
 	field = Clist->field > 0 ? Clist->field : 1;
 	fi = Vect_get_field(Map, field);
@@ -52,11 +59,8 @@
     have_colors = Vect_read_colors(Vect_get_name(Map), Vect_get_mapset(Map),
 				   &colors);
     
-    if (table_colors_flag) {
+    if (rgb_column) {
 	/* read RRR:GGG:BBB color strings from table */
-	if (!rgb_column || *rgb_column == '\0')
-	    G_fatal_error(_("Color definition column not specified"));
-	
 	db_CatValArray_init(&cvarr_rgb);
 	
 	nrec_rgb = db_select_CatValArray(driver, fi->table, fi->key,
@@ -64,12 +68,14 @@
 	
 	G_debug(3, "nrec_rgb (%s) = %d", rgb_column, nrec_rgb);
 	    
-	if (cvarr_rgb.ctype != DB_C_TYPE_STRING)
+	if (cvarr_rgb.ctype != DB_C_TYPE_STRING) {
 	    G_warning(_("Color definition column ('%s') not a string. "
 			"Column must be of form 'RRR:GGG:BBB' where RGB values range 0-255. "
 			"You can use '%s' module to define color rules. "
 			"Unable to colorize features."),
 		      rgb_column, "v.colors");
+            rgb_column = NULL;
+        }
 	else {
 	    if (nrec_rgb < 0)
 		G_fatal_error(_("Unable to select data ('%s') from table"),
@@ -196,7 +202,7 @@
 			     id_flag, cats_colors_flag,
 			     default_width, width_scale,
 			     z_color_flag ? &zcolors : NULL,
-			     table_colors_flag ? &cvarr_rgb : NULL,
+			     rgb_column ? &cvarr_rgb : NULL,
 			     have_colors ? &colors : NULL,
 			     &cvarr_width, nrec_width);
     
@@ -206,7 +212,7 @@
 			  id_flag, cats_colors_flag,
 			  default_width, width_scale,
 			  z_color_flag ? &zcolors : NULL,
-			  table_colors_flag ? &cvarr_rgb : NULL,
+			  rgb_column ? &cvarr_rgb : NULL,
 			  have_colors ? &colors : NULL,
 			  &cvarr_width, nrec_width,
 			  &cvarr_size, nrec_size,
@@ -251,13 +257,13 @@
 			line, cat, *red, *grn, *blu);
 	    }
 	    else {
-		G_important_message(_("Error in color definition (%s) - feature %d with category %d"),
-				    colorstring, line, cat);
+                G_debug(3, "Invalid color definition '%s' ignored", colorstring);
+                ncolor_rules_skipped++;
 		}
 	}
 	else {
-	    G_important_message(_("Error in color definition (%s) - feature %d with category %d"),
-				colorstring, line, cat);
+	    G_debug(3, "Invalid color definition '%s' ignored", colorstring);
+            ncolor_rules_skipped++;
 	}
     }
 



More information about the grass-commit mailing list