[GRASS5] r.mapcalc and float()

Glynn Clements glynn.clements at virgin.net
Mon May 3 14:07:04 EDT 2004


Markus Neteler wrote:

> while calculating the NDVI I found following r.mapcalc
> behaviour:
> 
> r.mapcalc "ndvi=float((lsat.4 - lsat.3)/(lsat.4+lsat.3))"
> r.info -r ndvi
> min=0.000000
> max=0.000000
> 
>  -> not desired
> 
> r.mapcalc "ndvi=float(1.0* (lsat.4 - lsat.3)/(lsat.4+lsat.3))"
> r.info -r ndvi
> min=-0.473684
> max=0.672727
> 
>  -> looks fine, but multiplication with 1. required
> 
> Is there a chance to change r.mapcalc to produce float
> when using float()?

float() does what it is supposed to, i.e. it converts its argument to
a float. In your fist example, the argument to float() is always
(integer) zero. Nothing which could be done to the float() function
would make it able to recover lost data.

If you want floating-point division, at least one of the arguments has
to be a floating-point value. Multiplying one of them by 1.0 will
produce a floating-point result, as will using float():

	r.mapcalc "ndvi=float(lsat.4 - lsat.3) / (lsat.4+lsat.3)"

-- 
Glynn Clements <glynn.clements at virgin.net>




More information about the grass-dev mailing list