[GRASS-SVN] r47649 - grass/trunk/vector/v.colors

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Aug 15 12:21:55 EDT 2011


Author: martinl
Date: 2011-08-15 09:21:55 -0700 (Mon, 15 Aug 2011)
New Revision: 47649

Added:
   grass/trunk/vector/v.colors/make_colors.c
Modified:
   grass/trunk/vector/v.colors/local_proto.h
   grass/trunk/vector/v.colors/main.c
   grass/trunk/vector/v.colors/scan_attr.c
   grass/trunk/vector/v.colors/scan_cats.c
Log:
v.colors: fix 'random' color table


Modified: grass/trunk/vector/v.colors/local_proto.h
===================================================================
--- grass/trunk/vector/v.colors/local_proto.h	2011-08-15 16:14:07 UTC (rev 47648)
+++ grass/trunk/vector/v.colors/local_proto.h	2011-08-15 16:21:55 UTC (rev 47649)
@@ -1,8 +1,11 @@
-/* scan_attr */
+/* make_colors.c */
+void make_colors(struct Colors *, const char *, DCELL, DCELL, int);
+
+/* scan_attr.c */
 int scan_attr(const struct Map_info *, int, const char *, const char *,
 	      const struct FPRange *, struct Colors *, int *, int *);
 
-/* scan_cats */
+/* scan_cats.c */
 void scan_cats(const struct Map_info *, int, const char *,
 	       const struct FPRange *, struct Colors *, int *, int *);
 

Modified: grass/trunk/vector/v.colors/main.c
===================================================================
--- grass/trunk/vector/v.colors/main.c	2011-08-15 16:14:07 UTC (rev 47648)
+++ grass/trunk/vector/v.colors/main.c	2011-08-15 16:21:55 UTC (rev 47649)
@@ -15,7 +15,6 @@
  *
  **************************************************************/
 
-#include <string.h>
 #include <stdlib.h>
 
 #include <grass/gis.h>
@@ -246,25 +245,6 @@
 	    scan_attr(&Map, layer, attrcolumn, style, opt.range->answer ? &range : NULL,
 		      &colors, &cmin, &cmax);
 	}
-	
-	if (strcmp(style, "random") == 0) {
-	    Rast_make_random_colors(&colors, (CELL) cmin, (CELL) cmax);
-	} else if (strcmp(style, "grey.eq") == 0) {
-	    G_fatal_error(_("Color table <%s> not supported"), "grey.eq");
-	    /*
-	      if (!have_stats)
-	      have_stats = get_stats(name, mapset, &statf);
-	      Rast_make_histogram_eq_colors(&colors, &statf);
-	    */
-        } else if (strcmp(style, "grey.log") == 0) {
-	    G_fatal_error(_("Color table <%s> not supported"), "grey.log");
-	    /*
-	      if (!have_stats)
-	      have_stats = get_stats(name, mapset, &statf);
-	      Rast_make_histogram_log_colors(&colors, &statf, (CELL) min,
-	      (CELL) max);
-	    */
-	}
     }
     else if (rules) {
 	if (!Rast_load_colors(&colors, rules, (CELL) cmin, (CELL) cmax))

Added: grass/trunk/vector/v.colors/make_colors.c
===================================================================
--- grass/trunk/vector/v.colors/make_colors.c	                        (rev 0)
+++ grass/trunk/vector/v.colors/make_colors.c	2011-08-15 16:21:55 UTC (rev 47649)
@@ -0,0 +1,39 @@
+#include <string.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/glocale.h>
+
+void make_colors(struct Colors *colors, const char *style, DCELL min, DCELL max, int is_fp)
+{
+
+    G_debug(3, "make_colors(): range=%f,%f is_fp=%d", min, max, is_fp);
+
+    if (strcmp(style, "random") == 0) {
+	if (is_fp)
+	    G_fatal_error(_("Color table '%s' is not supported for "
+			    "floating point attributes"), style);
+	Rast_make_random_colors(colors, (CELL) min, (CELL) max);
+    } else if (strcmp(style, "grey.eq") == 0) {
+	G_fatal_error(_("Color table <%s> not supported"), "grey.eq");
+	/*
+	  if (!have_stats)
+	  have_stats = get_stats(name, mapset, &statf);
+	  Rast_make_histogram_eq_colors(&colors, &statf);
+	*/
+    } else if (strcmp(style, "grey.log") == 0) {
+	G_fatal_error(_("Color table <%s> not supported"), "grey.log");
+	/*
+	  if (!have_stats)
+	  have_stats = get_stats(name, mapset, &statf);
+	  Rast_make_histogram_log_colors(&colors, &statf, (CELL) min,
+	  (CELL) max);
+	*/
+    }
+    else {
+	if (is_fp)
+	    Rast_make_fp_colors(colors, style, min, max);
+	else
+	    Rast_make_colors(colors, style, (CELL) min, (CELL) max);
+    }
+}


Property changes on: grass/trunk/vector/v.colors/make_colors.c
___________________________________________________________________
Added: svn:mime-type
   + text/x-csrc
Added: svn:eol-style
   + native

Modified: grass/trunk/vector/v.colors/scan_attr.c
===================================================================
--- grass/trunk/vector/v.colors/scan_attr.c	2011-08-15 16:14:07 UTC (rev 47648)
+++ grass/trunk/vector/v.colors/scan_attr.c	2011-08-15 16:21:55 UTC (rev 47649)
@@ -68,9 +68,6 @@
 		G_warning(_("Max value (%f) is out of range %f,%f"),
 			  range->max, fmin, fmax);
 	}
-	
-	G_debug(3, "scan_attr(): range=%f,%f", fmin, fmax);
-	Rast_make_fp_colors(&vcolors, style, (DCELL) fmin, (DCELL) fmax);
     }
     else {
 	fmin = cvarr.value[0].val.i;
@@ -89,10 +86,8 @@
 		G_warning(_("Max value (%d) is out of range %d,%d"),
 			  (int) range->max, (int) fmin, (int) fmax);
 	}
-	
-	G_debug(3, "scan_attr(): range=%d,%d", (int) fmin, (int) fmax);
-	Rast_make_colors(&vcolors, style, (CELL) fmin, (CELL) fmax);
     }
+    make_colors(&vcolors, style, (DCELL) fmin, (DCELL) fmax, is_fp);
 
     /* color table for categories */
     for (i = 0; i < cvarr.n_values; i++) {
@@ -129,7 +124,7 @@
 		*cmax = cat;
 	}
     }
-	
+    
     db_close_database(driver);
 
     return is_fp;

Modified: grass/trunk/vector/v.colors/scan_cats.c
===================================================================
--- grass/trunk/vector/v.colors/scan_cats.c	2011-08-15 16:14:07 UTC (rev 47648)
+++ grass/trunk/vector/v.colors/scan_cats.c	2011-08-15 16:21:55 UTC (rev 47649)
@@ -45,8 +45,7 @@
 		      (int) range->max, *cmin, *cmax);
     }
     
-    G_debug(3, "scan_cats(): range=%d,%d", *cmin, *cmax);
-    Rast_make_colors(colors, style, (CELL) *cmin, (CELL) *cmax);
+    make_colors(colors, style, (DCELL) *cmin, (DCELL) *cmax, FALSE);
 
     Vect_destroy_cats_struct(Cats);
 }



More information about the grass-commit mailing list