[GRASSLIST:4230] Re: Batch processing ?
Glynn Clements
glynn.clements at virgin.net
Tue Aug 6 20:34:22 EDT 2002
cheg01 at attbi.com wrote:
> Is it possible to run Grass non-interactively from a unix script? I would
> like to program a series of data imports and projections that involve
> moving between different Locations and Mapsets and I cannot figure out how
> to switch between locations without shutting down and restarting Grass.
> When the shell script starts grass, it loses control and I am left in an
> interactive Grass session. Another solution would be to change between
> locations without leaving Grass. Any advice would be appreciated.
Within GRASS, you can change the location with e.g.:
g.gisenv set=LOCATION_NAME=newlocation
You may also need to change the mapset with e.g.:
g.gisenv set=MAPSET=newmapset
It may help to ensure that you are using the most recent version of
GRASS. A number of programs (mostly scripts) were changed quite
recently to ensure that they used the current settings from $GISRC,
rather than the settings which were in effect at the beginning of the
GRASS session.
You can bypass the normal startup altogether, provided that you set
any necessary environment variables. The following seems to work for
me:
GISBASE=/opt/grass5 # change this as necessary
GISRC=$HOME/.grassrc5
TCLTKGRASSBASE=$GISBASE/tcltkgrass
GRASS_GNUPLOT=gnuplot
GRASS_PAGER=cat
GRASS_PERL=perl
GRASS_TCLSH=tclsh
GRASS_WISH=wish
PATH=$GISBASE/bin:$GISBASE/scripts:$PATH
MANPATH=$GISBASE/man:$MANPATH
LD_LIBRARY_PATH=$GISBASE/lib:$LD_LIBRARY_PATH
export GISBASE GISRC TCLTKGRASSBASE
export GRASS_GNUPLOT GRASS_PAGER GRASS_PERL GRASS_TCLSH GRASS_WISH
export PATH MANPATH LD_LIBRARY_PATH
Note, however, that bypassing the session mechanism will bypass
certain safety checks, e.g.
1. The startup script uses the lock file $HOME/.gislock5 to ensure
that a given user cannot have multiple GRASS sessions active.
2. The etc/set_data program (the one which prompts for database,
location and mapset) won't allow you to select a mapset which you
don't own (in the sense of Unix file ownership).
A consequence of 1 and 2 is that no two sessions will have the same
current mapset. This eliminates race conditions which could otherwise
occur. If you bypass the startup, you need to take care of this
yourself.
3. The startup script sets the environment variable GIS_LOCK to the
PID of the process running etc/Init.sh. This value is used in locking
access to certain resources, specifically:
a) The FIFOs which are used for communicating with monitors. Any
version of GRASS5 which is less than a couple of years old uses
sockets by default; the sockets don't require locking, so this is
almost certainly a non-issue.
b) The digitiser used by v.digit. For non-interactive use, this is
also a non-issue.
--
Glynn Clements <glynn.clements at virgin.net>
More information about the grass-user
mailing list