[GRASS-user] Mapcalc for rounding float values

Hamish hamish_b at yahoo.com
Thu Feb 14 14:50:49 PST 2013


Rebecca wrote:
> I have a map of local elevation that I would like to alter the
> values of and re-class as a experiment to aid visualisation &
> interpretation.

firstly, the r.reclass module might help, as may r.contour.

> 1) Currently the cells are floating point with z-values like
> 0.0151666768416021 - I would like to do is round the elevation
> values to 2dp.

there are a couple ways to do it, here's one:
  r.mapcalc "map.2dp = int(0.5 + (map.15g * 100))/100.0"

the 0.5 is added because int() truncates instead of rounding.

another common way is with log(mapname,10), but the above
may be a little more obvious.

> 2) I also like to reclassify the resulting map into 5cm wide
> elevation ranges (reflecting the accuracy of the original data
> capture) e.g. 0-4.90cm, 5-9.90cm etc

erhm, I'm not exactly sure if that is a valid approach to look
at the problem of instrument quantization (I'm fairly sure it
isn't, both technically and fundamentally), but it is probably a
job for r.reclass if you really want to do it; or adjust the
multiply by--truncate--divide by r.mapcalc trick above to get
it to round to whatever interval you like.


Hamish


More information about the grass-user mailing list