[q] floating-point number?

Eric Miller egm2 at tidepool.com
Sat Feb 13 17:34:33 EST 1999


Sungwon Choi wrote:
> 
> Hello, everybody!!!
> Is there anybody who has ever used 'r.mapcalc' in GRASS5.0beta?
> 
> Here is my problem..
> As far as I know, Grass 5.0beta can support a floating-point number..
> but, when I run 'r.mapcalc' in GRASS5.0beta, the result  is always a
> kind of integer..
> That frustrates me...
> 
> Can anybody explain to me what's the problem and how I can represent the
> floating-point number?
> 
> Thanks in advance...
> 
>             Best Regards
>              Sungwon Choi
> 
> --------------------------------------
> Sungwon Choi
> GIS LAB.
> Center for Mineral Resources Research
> Korea University, Seoul, Korea
> Tel +82-2-953-1676
> Email : earthcom at cmrgis.korea.ac.kr
> Good Luck!!!
> -------------------------------------
My understanding is you cast your integer raster to a float, but that
the resulting raster will truncate to an int, so you may want to
multiply by a factor of ten.

Example:
ndvi = 100 * ((float(band_4) - float(band_2))/(float(band_4) +
float(band_2))

This would calculate the NDVI using bands 2 & 4 of TM. Since the
original ratio is between -1 and 1, multiplying it by 100 makes it -100
to 100.  I'm not using the 5.0 version, but in the 4.2.1 version I found
if I didn't multiply by a factor of ten I got an output raster of all
zero's (effectively NULLs). You could addittionally add 127 to the
equation before output to move the zero point to 127 and have an output
raster that is in the 0 - 255 range.  Then you don't have to worry about
zero meaning NULL, because you won't have any zero's unless you were
using a mask.
-- 
                    Eric G. Miller
mailto:egm2 at tidepool.com | http://www.tidepool.com/~egm2
---------------------------------------------------------
       In vino veritas [In wine there is truth]



More information about the grass-user mailing list