[GRASS-user] Trying to reclassify raster using non-linear functions in GRASS

Glynn Clements glynn at gclements.plus.com
Fri Nov 8 05:14:23 PST 2013


Gabriel Zorello Laporta wrote:

> I am using ArcInfo Workstation and Grid in order to to produce Gaussian
> functions of elevation from a DEM with minimum value at 800m, as follow:
> 
> elev_x800 = elev90 - 800
> elev_x800sq = pow(elev_x800, 2)
> elev_x800sqn = -1 * elev_x800sq
> elev_x800sqnd = elev_x800sqn / 500000
> elev_x800exp = exp(elev_x800sqnd)
> elev_x800gaus = elev_x800exp * 0.000798
> elev_x800gi = (elev_x800gaus * -11330) + 10.044
> 
> I was wondering how to apply that in GRASS (because I want to move towards
> Open Software). Can you help me?

You should be able to use those exact same expressions in r.mapcalc,
e.g.

	r.mapcalc <<EOF
	elev_x800 = elev90 - 800
	elev_x800sq = pow(elev_x800, 2)
	elev_x800sqn = -1 * elev_x800sq
	elev_x800sqnd = elev_x800sqn / 500000
	elev_x800exp = exp(elev_x800sqnd)
	elev_x800gaus = elev_x800exp * 0.000798
	elev_x800gi = (elev_x800gaus * -11330) + 10.044
	EOF

The above will write out each step as a map; if you only need the
final result (elev_x800gi), you can omit all of the intermediate steps
and use e.g.:

	r.mapcalc "elev_x800gi = (exp(-((elev90 - 800)^2) / 500000) * 0.000798 * -11330) + 10.044"

Or, if you want to keep the expressions in the above form but only
want the last one written out as a map, use eval(), e.g.:

	r.mapcalc <<EOF
	eval(elev_x800 = elev90 - 800,\
	     elev_x800sq = pow(elev_x800, 2),\
	     elev_x800sqn = -1 * elev_x800sq,\
	     elev_x800sqnd = elev_x800sqn / 500000,\
	     elev_x800exp = exp(elev_x800sqnd),\
	     elev_x800gaus = elev_x800exp * 0.000798)
	elev_x800gi = (elev_x800gaus * -11330) + 10.044
	EOF

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-user mailing list