[GRASS-dev] another not quiet GRASS command

Glynn Clements glynn at gclements.plus.com
Tue Sep 4 06:32:47 EDT 2007


Michael Barton wrote:

> > I'm not questioning whether it's necessary to switch mapsets. I'm
> > questioning whether modifying the existing $GISRC is the right
> > approach, or whether gis.m should create a new $GISRC solely for use
> > by the georectifier.
> > 
> > Personally, I'd suggest the latter.
> 
> OK. I see what you're getting at now. I'm not sure how to accomplish it.
> 
> The active GISRC is a tempfile ( /tmp/grass6-cmbarton-6824/gisrc on my
> machine). 
> 
> Will simply creating a new temporary file with different values for
> LOCATION_NAME and MAPSET have the effect of 'switching' to a different
> working location/mapset?

You also need to change $GISRC to refer to the new file.

> If so, how to get the current GRASS session to
> recognize this? 

You don't want the "current GRASS session" to recognise it. What you
want is for the commands run from the georectifier (and nothing else)
to recognise it.

In gis.m, "set env(GISRC) $tmp_gisrc" before calling such commands,
then set it back afterwards.

In Python, change GISRC in the environment passed to Popen() for such
commands, e.g.:

	env = os.environ.copy()
	env["GISRC"] = tmp_gisrc
	child = subprocess.Popen(cmd, env = env, ...)

> Does it even have to be a text file on disk somewhere or can it simply be
> set to a variable (e.g., Python data object) with the appropriate values?

It needs to be a text file.

> Can I just make a minimal GISRC with only location and mapset, or is it
> safer to copy whatever is in the currently active one and then modify
> location and mapset.

I suggest the latter. If creating a new one, you need at least
GISDBASE, LOCATION_NAME and MAPSET for all commands. The others should
be optional.

> My active one currently contains...
> 
> DIGITIZER: none
> GISDBASE: /Users/Shared/grassdata
> GRASS_DB_ENCODING: utf-8
> GRASS_ADDON_PATH: /Applications/Grass/GRASS-6.3.app/Contents/Resources/etc/gm/script
> MONITOR: x0
> LOCATION_NAME: xy
> MAPSET: test
> GRASS_RENDER_IMMEDIATE: TRUE
> GRASS_GUI: wx

[I don't know how the GRASS_RENDER_IMMEDIATE setting got there; that's
an environment variable.]

I have:

GISDBASE: /opt/grass-data
LOCATION_NAME: spearfish57
MAPSET: glynn
GRASS_DB_ENCODING: ascii
GRASS_GUI: text

GRASS_DB_ENCODING is only used by the form library. GRASS_GUI is used
to remember the -text/-gui/etc setting between sessions and to
determine whether --ui uses Tcl/Tk or wxPython. Neither of these are
relevant for non-interactive commands.

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




More information about the grass-dev mailing list