[GRASS-dev] Location and mapset name variables

Greetings

I’m developing a few scripts but a few r.mapcalc lines will depend on the location and mapset. I mean, I will have different factors for different Locations and mapsets.
Is there any variables with location names and mapsets?
And is it possibvle to use in if setences in GRASS Bash scripts or even in PERL Scripts? (I suppose So)

Thank you
Pedro Roma

Pedro Roma wrote:

I'm developing a few scripts but a few r.mapcalc lines will depend on the
location and mapset. I mean, I will have different factors for different
Locations and mapsets.
Is there any variables with location names and mapsets?
And is it possibvle to use in if setences in GRASS Bash scripts or even in
PERL Scripts? (I suppose So)

You can query GRASS variables using g.gisenv. You can set shell
variables with e.g.:

  MAPSET=`g.gisenv get=MAPSET`

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

Ok this is the easiest way to retrieve Location and Mapset in a Script right?
And I can use it in a If sentence without any problems?

On Wed, Feb 3, 2010 at 5:39 PM, Glynn Clements <glynn@gclements.plus.com> wrote:

Pedro Roma wrote:

I’m developing a few scripts but a few r.mapcalc lines will depend on the
location and mapset. I mean, I will have different factors for different
Locations and mapsets.
Is there any variables with location names and mapsets?
And is it possibvle to use in if setences in GRASS Bash scripts or even in
PERL Scripts? (I suppose So)

You can query GRASS variables using g.gisenv. You can set shell
variables with e.g.:

MAPSET=g.gisenv get=MAPSET


Glynn Clements <glynn@gclements.plus.com>

Pedro Roma wrote:

> > I'm developing a few scripts but a few r.mapcalc lines will depend on the
> > location and mapset. I mean, I will have different factors for different
> > Locations and mapsets.
> > Is there any variables with location names and mapsets?
> > And is it possibvle to use in if setences in GRASS Bash scripts or even
> in
> > PERL Scripts? (I suppose So)
>
> You can query GRASS variables using g.gisenv. You can set shell
> variables with e.g.:
>
> MAPSET=`g.gisenv get=MAPSET`

Ok this is the easiest way to retrieve Location and Mapset in a Script
right?

Yes.

And I can use it in a If sentence without any problems?

The shell expands variables within double-quoted strings and within
here documents, so you can use e.g.:

  r.mapcalc " ... $MAPSET ..."
or:
  r.mapcalc <<EOF
  ...
  ... $MAPSET ...
  ...
  EOF

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

So it’s possible also to use in r.mapcalc expressions? That is great.
I have tested in Bash Script If conditions and it works just fine.

By the way, is it also possible to use g.gisenv in a Script to change MAPSET or LOCATION without loosing messing image processing, I mean loosing path the Input and output data?
Thank you
Pedro

On Wed, Feb 3, 2010 at 10:06 PM, Glynn Clements <glynn@gclements.plus.com> wrote:

Pedro Roma wrote:

I’m developing a few scripts but a few r.mapcalc lines will depend on the
location and mapset. I mean, I will have different factors for different
Locations and mapsets.
Is there any variables with location names and mapsets?
And is it possibvle to use in if setences in GRASS Bash scripts or even
in
PERL Scripts? (I suppose So)

You can query GRASS variables using g.gisenv. You can set shell
variables with e.g.:

MAPSET=g.gisenv get=MAPSET

Ok this is the easiest way to retrieve Location and Mapset in a Script
right?

Yes.

And I can use it in a If sentence without any problems?

The shell expands variables within double-quoted strings and within
here documents, so you can use e.g.:

r.mapcalc " … $MAPSET …"
or:
r.mapcalc <<EOF

… $MAPSET …

EOF

Glynn Clements <glynn@gclements.plus.com>

Pedro Roma wrote:

So it's possible also to use in r.mapcalc expressions? That is great.
I have tested in Bash Script If conditions and it works just fine.

r.mapcalc knows nothing about GRASS varibles, shell variables or
environment variables. However, the shell will substitute shell
variables and environment variables in double quoted strings.
r.mapcalc just sees the end result.

By the way, is it also possible to use g.gisenv in a Script to change MAPSET
or LOCATION without loosing messing image processing, I mean loosing path
the Input and output data?

I would advise against changing location/mapset in a script.

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