[GRASS-dev] Re: [GRASS-user] Errors applying color rules and -g flags in r.colors

Glynn Clements glynn at gclements.plus.com
Thu Apr 19 13:22:47 EDT 2007


Patton, Eric wrote:

> I'm having trouble getting the new r.color -g flag to do anything. Or,
> more correctly, maybe it's working properly, but I just can't tell if
> it's doing anything or not.
> 
> Running r.colors -g produces a blank display in gis.m on an ordinary raster dataset:
> 
> ~ >g.region rast=IsaacsHarbour_HDCS_1m_grd_fill at PERMANENT
> ~ >
> ~ >r.colors -g map=IsaacsHarbour_HDCS_1m_grd_fill at PERMANENT color=rainbow
> Color table for [IsaacsHarbour_HDCS_1m_grd_fill at PERMANENT] set to rainbow
> ~ >

Can you provide details of the map, specifically whether it is integer
or FP, and the range?

> I'm also getting errors applying several of the new-ish predefined
> color tables. I've ran a script to apply each color table in turn to
> the same input raster. Output pasted below (warning, it's long):
> 
> for COLOR in `r.colors -l` ; do
> echo -e "\n\nApplying color rule $COLOR to input raster...\n"
> r.colors map=IsaacsHarbour_HDCS_1m_grd_fill at PERMANENT color=$COLOR
> done
> 
> 
> Applying color rule aspect to input raster...
> 
> Color table for [IsaacsHarbour_HDCS_1m_grd_fill at PERMANENT] set to aspect
> 
> 
> Applying color rule aspectcolr to input raster...
> 
> ERROR: bad rule (percentage not in range 0-100): 180 cyan

This is a bug in the new code; I forgot that:

	if (sscanf(value, "%lf%%", &x) == 1)

will be true regardless of whether or not there is a percent sign
after the value, so it's treating all values as percentages. I'll
commit the following change shortly:

Index: lib/gis/color_rules.c
===================================================================
RCS file: /grassrepository/grass6/lib/gis/color_rules.c,v
retrieving revision 1.3
diff -u -r1.3 color_rules.c
--- lib/gis/color_rules.c	14 Apr 2007 03:35:32 -0000	1.3
+++ lib/gis/color_rules.c	19 Apr 2007 17:15:57 -0000
@@ -46,6 +46,7 @@
 {
     char value[16], color[16];
     double x;
+    char c;
 
     *norm = *nval = *dflt = 0;
 
@@ -86,7 +87,7 @@
 	return CR_OK;
     }
 
-    if (sscanf(value, "%lf%%", &x) == 1)
+    if (sscanf(value, "%lf%c", &x, &c) == 2 && c == '%')
     {
 	if (x < 0 || x > 100)
 	    return CR_ERROR_PERCENT;

> So in sum, there are problems applying the aspectcolr, curvature,
> etopo2, evi, ndvi, population, srtm, and terrain color tables. It
> seems that r.colors will only accept a percentage color range and not
> a standard Grass color name or RGB value.

Yep. Thanks for finding this.

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-dev mailing list