[GRASS-user] Suggestion for creating a script to create a map of agricultural capacity
Glynn Clements
glynn at gclements.plus.com
Wed May 29 15:30:39 PDT 2013
Hamish wrote:
> > But for this specific case, it's probably simpler to just
> > generate an integer version of the slope map (if it isn't
> > already) and use r.reclass, e.g.
> >
> > r.reclass input=slope output=slope.reclass rules=- <<EOF
> > 0 thru 2 = 1
> > 3 thru 5 = 2
> > 6 thru 10 = 3
> > 11 thru 15 = 4
> > 16 thru 45 = 5
> > 46 thru 70 = 6
> > * = 7
> > EOF
>
> note that r.reclass can read floating point maps too, but
> it's a bit buggy/weird,
> https://trac.osgeo.org/grass/ticket/1525#comment:10
Right; r.reclass just generates the table, the actuall reclass is
performed by lib/raster. If the base map is floating-point, it will be
coerced to integer using its associated quantisation rules.
Note that r.reclass doesn't pay any attention to the map's
quantisation rules (even if it did, they could be changed between the
reclass being created and being used, and the rules at the time of use
would have effect).
The buggy rounding code should probably be replaced with e.g.
*v = (CELL) floor(fv + 0.5);
or:
*v = (CELL) ceil(fv - 0.5);
or:
*v = (CELL) (fv > 0 ? floor(fv + 0.5) : ceil(fv - 0.5));
These differ on whether values lying exactly on a 0.5 boundary are
rounded toward positive infinity, toward negative infinity, or away
from zero respectively. The last one mimics the behaviour of C99's
round() function.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-user
mailing list