[GRASS-dev] Using GRASS to calculate an index
Glynn Clements
glynn at gclements.plus.com
Mon Nov 23 18:06:08 EST 2009
Luis Lisboa wrote:
> I'm planning on developing an index to use over RASter images. Is quite an
> easy expression with a few sums and square roots. All those operations are
> included in r.mapcalc but instead of doing each operation using image
> calculation in GUI I want to do an automatic procedure in which I select
> image A, image B and Image C and he does the rest.
> I can use a script file but I want the user to select which is image A, B
> and C and only then the script process the images.
> Question: How can I call a wxpython form (just like the others) from a
> script file?
The GUI parameter forms are auto-generated from the parameter
descriptions (the same information that is used for the --help output
and the HTML documentation).
If you look at any of the provided scripts (in the "scripts"
directory), you will see that they start with a block of comments like
(this example was taken from r.blend):
#%Module
#% description: Blends color components of two raster maps by a given ratio.
#% keywords: raster
#%End
#%option
#% key: first
#% type: string
#% gisprompt: old,cell,raster
#% description: Name of first raster map for blending
#% key_desc : name
#% required : yes
#%end
Shortly after the comments will be something like:
if [ "$1" != "@ARGS_PARSED@" ] ; then
exec g.parser "$0" "$@"
fi
The g.parser module reads the script, and uses the comments to
generate a parameter dialog. Once the user fills in the parameters and
presses "OK", the script is executed with the supplied parameters
passed through environment variables (and with the string
"@ARGS_PARSED@" as the only argument, so that it doesn't just call
g.parser again).
See the g.parser manual page for more details.
This mechanism can be used in any language which treats the "#"
character as starting a comment (although for Python, there is a
standardised framework for scripts which includes an interface to
g.parser).
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list