[GRASS-user] r.fillnulls error
Glynn Clements
glynn at gclements.plus.com
Sat Sep 10 06:53:28 EDT 2011
Hamish wrote:
> I am not sure if "$input" needs to be quoted or not in the
> trunk python version:
>
> #creating 0/1 map:
> grass.mapcalc("$tmp1 = if(isnull($input),1,null())",
> tmp1 = tmp1, input = input)
If a map name can be interpreted as a number[1], or it contains any
non-alphanumeric characters which are syntactically significant to
r.mapcalc, then it must be quoted.
[1] This includes incomplete floating-point values such as "1.2e"; in
order to produce reasonable error messages, the token grammar includes
a rule which specifically matches such cases.
The substitutions in the mapcalc() function are direct textual
substitutions performed within Python before the resulting string is
passed to r.mapcalc, so the above needs quotes around $input in order
to correctly handle "unusual" map names.
This is probably the case for most such calls, except those where the
map name is dictated by the script.
I suppose that it would be possible to have the mapcalc() function
automatically add quotes to any arguments which are strings. However,
this would break scripts which pass option values directly to
mapcalc() without parsing them to an int/float first. It would also
preclude cases such as:
grass.mapcalc("$outmap = $func($inmap)", func = 'sqrt', ...)
unless we add yet more complexity (e.g. names ending in "_raw" aren't
quoted, or similar).
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-user
mailing list