[GRASS5] [bug #1401] (grass) possible d.legend enhancements?

Request Tracker grass-bugs at intevation.de
Thu Nov 7 22:32:25 EST 2002

this bug's URL: http://intevation.de/rt/webrt?serial_num=1401

Subject: possible d.legend enhancements?

Platform: GNU/Linux/i386
grass obtained from: Mirror of Trento site
grass binary for platform: Compiled from Sources
GRASS Version: 5.0.0

Several wishes here, but they are all related.

When using d.legend with floating point rasters, the legend goes from smallest value at the top to largest at the bottom. While this is proper for category values, it seems backwards for typical floating point data. I am mostly thinking about elevation scales, but I think it holds for most physical data.

It would be nice if d.legend checked to see if the raster was int or float, and flip the output accordingly for floats. I'd guess this is what people would want most of the time, but for when it wasn't the desired output, maybe have the user set the first corner down lower on the screen than the second corner, which would have the effect of flipping it again (both to reverse integer category legends or floating point data legends)
flip = 0;
if( isfloat(rast) ) { flip = 1; }
if( corner1_y > corner2_y) { flip = !flip; }

It would aslo be nice if the floating point legend didn't always report to six decimal point accuracy, as it is more information than is usually relevant, and clutters the display.

I propose the following:
  For data ranges greater than 25, no decimal points would be used.
  eg Legend: 0 100 200 300 400

  For data ranges more than 2.5, but less than 25.0, one would be used.
  eg Legend: 0.0 1.0 2.0 3.0 4.0

  For data ranges more than 0.25, but less than 2.5, two would be used.
  eg Legend: 0.0 0.10 0.20 0.30 0.40

and so on.

here's a little C program to demonstrate how this could be easily done:

#include <stdio.h>
#include <math.h>		// gcc -lm

int main() {
	float rangeMax = 2.54, rangeMin = 0.0;
	int SigDigits;
	char DispFormat[5];	// %.Xf\0

	SigDigits = ceil(log10(fabs(25/(rangeMax - rangeMin))));
	if(SigDigits < 0) { SigDigits = 0; }
	sprintf(DispFormat, "%%.%df", SigDigits);

	printf(DispFormat, rangeMax);
	printf(DispFormat, rangeMin);

	return 0;

Yet another point for refinement might be to extend the range limits up to nice round numbers, so instead of 0.213455 -> 91.435678 the legend text would go 0 -> 100. ??

Maybe instead take the range from the top line of the color map file in $MAPSET/colr? (to allow refinement by the user)

A 'at=x1,y1,x2,y2' command line option would be nice too, to make the module  scriptable and repeatable (eg for multiple hardcopies).

<ihatejunkyabastards at yahoo.com>

-------------------------------------------- Managed by Request Tracker

More information about the grass-dev mailing list