[GRASS-dev] Access to mapset environment variable

Dear all,
I am struggling to access GRASS mapset specific environmental
variables from mapsets different than the current one in C.

I tried the following code to access temporal database settings of
other mapsets:

{{{
    G_create_alt_env();
    G__setenv("GISDBASE", gisdbase_name);
    G__setenv("LOCATION_NAME", location_name);
    G__setenv("MAPSET", mapset);

    if(contype == DATABASE_NAME) {
        if ((val = G__getenv2("TGISDB_DATABASE", G_VAR_MAPSET)))
            ret_val = G_store(val);
    } else if(contype == DRIVER_NAME) {
        if ((val = G__getenv2("TGISDB_DRIVER", G_VAR_MAPSET)))
            ret_val = G_store(val);
    }
    G_switch_env();

}}}

But it does not work, the specified TGIS driver and database strings
are not found.

Without switching the environment only the TGIS variables of the
current mapset are read, not from the ones from a mapset set with
G_setenv("MAPSET", mapset).

Is there a possibility to access mapset specific environmental
variables in C from a different mapset as the current one?

Any help is really appreciated,
best regards
Soeren

Sören wrote:

I am struggling to access GRASS mapset specific environmental
variables from mapsets different than the current one in C.

...

Is there a possibility to access mapset specific environmental
variables in C from a different mapset as the current one?

Hi,

I would suggest to use the mapsets' VAR file, not gisrc (g.gisenv),
to store per-mapset variables like that. Since gisrc is per-session
and ephemeral, not per-mapset and remembered after the session is
closed.

hope it helps,
Hamish

Hi Hamish,
Thanks for your answer.
Am 04.09.2014 00:19 schrieb “Hamish” <hamish.webmail@gmail.com>:

Sören wrote:

I am struggling to access GRASS mapset specific environmental
variables from mapsets different than the current one in C.

Is there a possibility to access mapset specific environmental
variables in C from a different mapset as the current one?

Hi,

I would suggest to use the mapsets’ VAR file, not gisrc (g.gisenv),
to store per-mapset variables like that. Since gisrc is per-session
and ephemeral, not per-mapset and remembered after the session is
closed.

Actually that is exactly what i am trying to do. So my question is how to convince grass to read the VAR file from a mapset other than the current one without invoking g.mapset.

Best regards
Soeren

hope it helps,
Hamish

Sören Gebbert wrote:

> > I am struggling to access GRASS mapset specific environmental
> > variables from mapsets different than the current one in C.
> ...
> > Is there a possibility to access mapset specific environmental
> > variables in C from a different mapset as the current one?
>
> Hi,
>
> I would suggest to use the mapsets' VAR file, not gisrc (g.gisenv),
> to store per-mapset variables like that. Since gisrc is per-session
> and ephemeral, not per-mapset and remembered after the session is
> closed.

Actually that is exactly what i am trying to do. So my question is how to
convince grass to read the VAR file from a mapset other than the current
one without invoking g.mapset.

Currently, you can't. G__gisinit() calls G_init_env() which reads both
environment files into memory. The functions which read these files
will not attempt to read them again if they're already in memory.

You would need to modify lib/gis/env.c to allow the "VAR" environment
to be forcibly re-read (and without first re-reading the "gisrc"
environment, as that will restore the original current mapset).

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

Hi,

2014-09-04 23:04 GMT+02:00 Glynn Clements <glynn@gclements.plus.com>:

Sören Gebbert wrote:

> > I am struggling to access GRASS mapset specific environmental
> > variables from mapsets different than the current one in C.
> ...
> > Is there a possibility to access mapset specific environmental
> > variables in C from a different mapset as the current one?
>
> Hi,
>
> I would suggest to use the mapsets' VAR file, not gisrc (g.gisenv),
> to store per-mapset variables like that. Since gisrc is per-session
> and ephemeral, not per-mapset and remembered after the session is
> closed.

Actually that is exactly what i am trying to do. So my question is how to
convince grass to read the VAR file from a mapset other than the current
one without invoking g.mapset.

Currently, you can't. G__gisinit() calls G_init_env() which reads both
environment files into memory. The functions which read these files
will not attempt to read them again if they're already in memory.

You would need to modify lib/gis/env.c to allow the "VAR" environment
to be forcibly re-read (and without first re-reading the "gisrc"
environment, as that will restore the original current mapset).#

Thank you for this clear answer. I have implemented a patch to allow
force reading
of mapset VAR and gisrc files in libgis[1] including some tests. I
would like to submit it in the next week, if there are no objections
against the patch?

Best regards
Soeren

[1] http://trac.osgeo.org/grass/ticket/2408

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