[GRASS-user] legend scientific format

Hamish hamish_b at yahoo.com
Tue Nov 15 19:17:29 EST 2011

> > I want to generate a map legend  with number in
> > scientific format. (I have number like 1.0E+14
> and in the legend appear like 100000000000000)…

> Do you use d.legend?
> http://grass.osgeo.org/grass64/manuals/html64_user/d.legend.html
> "The text produced from floating-point raster maps will
> automatically create
> output with a meaningful number of significant digits. For
> very small values,
> numbers will be expressed in scientific notation, e.g.
> "1.7e-9".
> "
> Perhaps that should be likewise implemented for
> very large numbers, too?

It is based on the data's range.

for the morbidly curious, 

        /* determine how many significant digits to display based on range */
        if (0 == (dmax - dmin)) /* trap divide by 0 for single value rasters */
            sprintf(DispFormat, "%%f");
        else {
            SigDigits = (int)ceil(log10(fabs(25 / (dmax - dmin))));
            if (SigDigits < 0)
                SigDigits = 0;
            if (SigDigits < 7)
                sprintf(DispFormat, "%%.%df", SigDigits);
                sprintf(DispFormat, "%%.2g");   /* eg 4.2e-9  */

The idea being that if the legend range is 1e6 to
-1e6 it just clutters the page to show so many

At the time I wrote that code I was using r.sun a
lot, so I'll go back and see what the old annual
solar irradiation plots were looking like, as those
numbers get pretty big too.

What threshold to use for the switchover to sci/eng
format? >=10million?


More information about the grass-user mailing list