[GRASS-dev] any way to know color assigned to a cell?
hamish_nospam at yahoo.com
Wed Apr 18 09:51:16 EDT 2007
> >> If have a map with values from 0-255 I create a set of color rules
> >> such that
> >> 0% = green
> >> 100% = red
> >> GRASS will create a color table that will assign a nice gradient of
> >> colors from 0:255:0 to 255:0:0 to the values from 0-255.
> >> Is there any way when querying a single cell of that map to know
> >> what color has been assigned to it?
> > Set a 1x1 region around the cell, then r.out.ppm | pnmnoraw | sed.
> > Or r.mapcalc 'out = (r#map * 256 + g#map) * 256 + b#map', query the
> > composite map and decode the category number.
> >> Similarly, is there any way to know what color has
> >> been assigned to any value in the 0-255 range?
> > Set a 1x1 region, r.mapcalc "tmp = $value", r.out.ppm ...
> > Seriously; this is how d.rast.edit.tcl does it.
> > Yeah; we could probably do with a "r.what.colors" module.
> I was contemplating a wxPython histograming module, like the TclTk
> profiling module, and liked the option in d.histogram of being able to
> use the color table for the histogram colors. But this seems like a
> pretty intensive batch of calculations to do it.
you could try "r.profile -c" with a profile which starts and stops at
the cell center (length=0). Also it should be very simple to add a flag
just like "r.profile -c" to r.what, if that helps.
But probably the most direct solution is a SWIG-Python interface to the
libgis color-lookup fns themselves.
More information about the grass-dev