[GRASS-dev] G__getenv return different results from ctypes and from GRASS modules

Pietro Zambelli peter.zamb at gmail.com
Sat Jun 1 13:33:48 PDT 2013


On Saturday 01 Jun 2013 01:48:39 Glynn Clements wrote:
> Nikos Alexandris wrote:
> > > > Why the ctypes version return 'PERMANENT' instead of 'user1'?
> > 
> > Glynn Clements wrote:
> > > The $GISRC file is read the first time that an environment lookup is
> > > made. There is no way to force it to be re-read.
> > 
> > This means that I can't use instructions like
> 
> [...]
> 
> > in a function (pasted below) which I call from within a "for" loop to go
> > through Mapsets that potentially contain raster maps named differently?
> 
> You can modify the current process' environment with G_setenv().

Or use the method

current() => to set the mapset as current

I completely forgot that I've already implemented this functionalities... :-)

see this example:

{{{
In [1]: from grass.pygrass.gis import Mapset
In [2]: veg = Mapset()
In [3]: veg
Out[3]: Mapset('veg')
In [5]: perm = Mapset('PERMANENT')
In [6]: perm.is_current()
Out[6]: False
In [7]: veg.is_current()
Out[7]: True
In [8]: !g.mapset -p
veg
In [9]: perm.current()
In [10]: !g.mapset -p
PERMANENT
In [11]: perm.is_current()
Out[11]: True
In [12]: veg.is_current()
Out[12]: False
}}}


More information about the grass-dev mailing list