[GRASS-dev] Re: [GRASS-SVN] r33576 - grass/trunk/lib/gis

Glynn Clements glynn at gclements.plus.com
Sun Sep 28 12:19:47 EDT 2008


Markus Neteler wrote:

> > Modified:
> >   grass/trunk/lib/gis/parser.c
> > Log:
> > More restrictive test for option: [a-z0-9_]*[a-z0-9]
> >  i.e. must consist solely of [a-z0-9_], and the last character may not be an underscore
> >  [can we change 3dview= so that the first character must also be alphabetic?]
> 
> I guess that view3d is also fine (I don't even remember what it does,
> is it needed at all?).

I think that it's mainly for NVIZ, although g.region and r.region can
set the region from a 3dview.

In any case, it's no longer relevant. Apart from the issue of overall
consistency, there were two specific issues:

1. r.mapcalc now uses G_parser(). You can still use e.g.:

	r.mapcalc "map = ..."

(where the expression is quoted) as a shorthand for:

	r.mapcalc expression = "map = ..."

so long as the parser doesn't mistake the expression for an option.

If there is a space before the first '=', there's no problem. 
Similarly, if the map name isn't a valid option name, there's no
problem. Hence the desire to limit the definition of what constitutes
an option name to what is normally used.

However, given that typical map names are also valid option names, in
most cases it will be necessary to place a space before the first '='
sign, e.g.:

	r.mapcalc 'a = b+c'

rather than:

	r.mapcalc 'a=b+c'

as the latter will complain about a= not being a valid option.

2. The Python functions grass.run_command() etc accept arbitrary
keword arguments, which are passed verbatim onto the module, e.g.:

	grass.run_command('g.list', type = 'rast')

will execute:

	g.list type=rast

But this requires that the option name is a valid Python identifier,
i.e. it conforms to the general syntax and isn't a keyword. You can
still get around this with e.g.:

	lambda_opt = {'lambda': 0.5}
	grass.run_command('r.walk', ..., **lambda_opt)

but it's ugly. In the end, I solved this issue by allowing options to
be given a leading underscore, e.g.:

	grass.run_command('r.walk', ..., _lambda = ...)
or:
	grass.run_command('g.remove', _3dview = ...)

The leading underscore is simply discarded.

However, this did necessitate changing the dots in some r.watershed
options to underscores (no other module used this syntax). For
consistency, r.topmodel's Qobs= was changed to qobs=, as that was the
only remaining instance of an upper-case character in an option name
(r.terraflow's STREAM_DIR= was changed to stream_dir= a while back).

The end result is that option names are restricted to lower-case
letters, digits, and underscores, and cannot begin or end with an
underscore.

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


More information about the grass-dev mailing list