[GRASS-user] mapcalc problem in python script!!

Glynn Clements glynn at gclements.plus.com
Tue Feb 8 20:37:43 EST 2011

Johannes Radinger wrote:

> > > Somehow I didn't your answer via email, I just found it at
> > > http://permalink.gmane.org/gmane.comp.gis.grass.user/38530
> > 
> > For whatever reason, GMX doesn't like my IP address, and bounces my
> > emails. The problem is compounded by a "feature" of the mailing list
> > software which (by default) doesn't send messages to any subscriber
> > whose email address appears in the To or CC fields (on the assumption
> > that they'll already get a copy). You can (and probably should)
> > disable this feature in your preferences (via the link at the bottom
> > of the email).
> I don't know which feature to disable?!?

Use the link at the bottom of the page to edit your subscription
options. The option in question is labelled "Avoid duplicate copies of
messages?", and should be set to "no".

> > grass.parser() needs to know the valid options for the script. These
> > are specified by comments beginning with "#%". See any existing script
> > for reference.
> > 
> > Then, you need to run the script with the appropriate command line
> > options. I'm assuming that isn't happening, because you should get an
> > error if you provide an unrecognised option (and there are no
> > recognised options).
> I added your comments "#%" in the script (see attachment). Is it the
> only way to run the grass.mapcalc version in python with the
> grass.parser? I run my script external, directly from IDLE (without
> starting grass).

That won't work. Starting GRASS sets several environment variables
required by the GRASS libraries. If you want to be able to run GRASS
commands from anywhere, you will have to configure the environment
variables yourself.

The following is a minimal setup for Linux:

	export GISBASE=/opt/grass-7.0.svn
	export GRASS_PAGER=cat
	export GRASS_PYTHON=python
	export PATH="$GISBASE/bin:$GISBASE/scripts:$PATH"
	export GIS_LOCK=$$
	export GRASS_VERSION="7.0.svn"
	export GISRC="$tmp/gisrc"
	mkdir "$tmp"
	cp ~/.grassrc6 "$GISRC"

On Windows, the paths will be different, and you need to set PATH
rather than LD_LIBRARY_PATH for the libraries.

The most important of the above are GISBASE, which must point to the
top-level GRASS installation directory, and GISRC, which must point to
a file containing settings for GISDBASE, LOCATION_NAME and MAPSET.

Glynn Clements <glynn at gclements.plus.com>

More information about the grass-user mailing list