[GRASS-user] Use variables in GUI?

  This may be beyond Grass-GIS, but here goes.

I have to generate many output maps (50) and I need transparency - which means I can't just use d.vect and d.out.file in a script.

But in the outputs, I have to restrict the display to a named area (eg: state="NSW").

So I'm wondering - is there any way within the GUI - either TCL or Python - to use a variable within the SQL query?

That way, it may show "state=$variable" in the select window, and I just need to set the variable, zoom to a region, and produce an output rather than having to adjust the variable in 50 or so outputs!

Richard

Richard wrote:

This may be beyond Grass-GIS, but here goes.

nothing is impossible :slight_smile:

I have to generate many output maps (50) and I need
transparency - which means I can't just use d.vect and
d.out.file in a script.

i.e. you need blending? that is done for the GUI by the g.pnmcomp
module.
Use the PNG driver (it is map filename extension aware to avoid .png)
or d.out.file to create the files. or just use NetPBM's version of
pnmcomp yourself.

But in the outputs, I have to restrict the display to a
named area (eg: state="NSW").

So I'm wondering - is there any way within the GUI - either
TCL or Python - to use a variable within the SQL query?

That way, it may show "state=$variable" in the select
window, and I just need to set the variable, zoom to a
region, and produce an output rather than having to adjust
the variable in 50 or so outputs!

my only idea would be to write a script which created a GUI session
file dynamically, then load those. but g.pnmcomp could bypass the issue?

Also of note, r.out.png in 6.5svn has a new -t flag to make the NULL cells
transparent, and a new -w flag to output a world file. r.out.tiff will get
the same for NULL cells at some point. The main reason for this is that it
makes nice rasters for WMS, TMS, gdal2tiles & OpenLayers web maps. I see
no reason why these shouldn't be backported to 6.4.1 after some quick
testing in 6.5. (trac #1077)

Hamish

  Hamish - thanks, I'll see if g.pnmcomp takes care of things and let you know!

Cheers,
Richard

On 24/09/10 11:43 AM, Hamish wrote:

Richard wrote:

  This may be beyond Grass-GIS, but here goes.

nothing is impossible :slight_smile:

I have to generate many output maps (50) and I need
transparency - which means I can't just use d.vect and
d.out.file in a script.

i.e. you need blending? that is done for the GUI by the g.pnmcomp
module.
Use the PNG driver (it is map filename extension aware to avoid .png)
or d.out.file to create the files. or just use NetPBM's version of
pnmcomp yourself.

But in the outputs, I have to restrict the display to a
named area (eg: state="NSW").

So I'm wondering - is there any way within the GUI - either
TCL or Python - to use a variable within the SQL query?

That way, it may show "state=$variable" in the select
window, and I just need to set the variable, zoom to a
region, and produce an output rather than having to adjust
the variable in 50 or so outputs!

my only idea would be to write a script which created a GUI session
file dynamically, then load those. but g.pnmcomp could bypass the issue?

Also of note, r.out.png in 6.5svn has a new -t flag to make the NULL cells
transparent, and a new -w flag to output a world file. r.out.tiff will get
the same for NULL cells at some point. The main reason for this is that it
makes nice rasters for WMS, TMS, gdal2tiles& OpenLayers web maps. I see
no reason why these shouldn't be backported to 6.4.1 after some quick
testing in 6.5. (trac #1077)

Hamish

  Hamish,

Being more a scripter than a programmer, I suspect g.pnmcomp is beyond me ... I can't really see how to pass a map to the module, and can't really find any examples to help.

So here's what I would like (ideally) a script to do:

1. set a variable (eg state)
for i in NSW QLD VIC; do
g.region vect=$i

2. Load gis.m with a .grc file
gis.m dmrc=Mymaps.grc

3. Pass $i to the "where" variable in a vector.

4. Zoom to the region.

5. Output the image to $i.png

6. Quit gis.m for the next state.

Is it feasible?

Cheers,
Richard
On 24/09/10 11:43 AM, Hamish wrote:

Richard wrote:

  This may be beyond Grass-GIS, but here goes.

nothing is impossible :slight_smile:

I have to generate many output maps (50) and I need
transparency - which means I can't just use d.vect and
d.out.file in a script.

i.e. you need blending? that is done for the GUI by the g.pnmcomp
module.
Use the PNG driver (it is map filename extension aware to avoid .png)
or d.out.file to create the files. or just use NetPBM's version of
pnmcomp yourself.

But in the outputs, I have to restrict the display to a
named area (eg: state="NSW").

So I'm wondering - is there any way within the GUI - either
TCL or Python - to use a variable within the SQL query?

That way, it may show "state=$variable" in the select
window, and I just need to set the variable, zoom to a
region, and produce an output rather than having to adjust
the variable in 50 or so outputs!

my only idea would be to write a script which created a GUI session
file dynamically, then load those. but g.pnmcomp could bypass the issue?

Also of note, r.out.png in 6.5svn has a new -t flag to make the NULL cells
transparent, and a new -w flag to output a world file. r.out.tiff will get
the same for NULL cells at some point. The main reason for this is that it
makes nice rasters for WMS, TMS, gdal2tiles& OpenLayers web maps. I see
no reason why these shouldn't be backported to 6.4.1 after some quick
testing in 6.5. (trac #1077)

Hamish

Richard wrote:

Being more a scripter than a programmer, I suspect
g.pnmcomp is beyond me ... I can't really see how to pass a
map to the module, and can't really find any examples to help.

#spearfish example:
r.shaded.relief map=elevation.dem shade=elev.shade

g.region rast=elev.shade
d.mon x0
d.resize # ...

d.erase
d.rast elev.shade
d.out.file -t output=background format=ppm

d.erase
d.rast -o fields
d.out.file -t output=overlay format=ppm

d.erase
d.vect roads
d.out.file -t output=foreground format=ppm

d.erase
d.legend -c fields thin=4
d.barscale at=62.5,94
d.out.file -t output=decorations format=ppm

g.pnmcomp input=background.ppm,overlay.ppm,foreground.ppm,decorations.ppm \
   mask=background.pgm,overlay.pgm,foreground.pgm,decorations.pgm \
   output=merged.ppm outmask=merged.pgm opacity=1,0.5,1,0.8 \
   width=`d.info -d | cut -f2 -d' '` height=`d.info -d | cut -f3 -d' '`

#from netpbm tools, see also the man page for 'pnmcomp'
pnmtopng merged.ppm > merged.png

(GRASS's g.pnmcomp is rather poorly documented)

So here's what I would like (ideally) a script to do:

1. set a variable (eg state)
for i in NSW QLD VIC; do
g.region vect=$i

2. Load gis.m with a .grc file
gis.m dmrc=Mymaps.grc

use d.* instead,

3. Pass $i to the "where" variable in a vector.

4. Zoom to the region.

5. Output the image to $i.png

6. Quit gis.m for the next state.

Is it feasible?

technically you could set up a gis.m .grc file from a script,
it's just a text file.. but I think you can do all you want
with a script like the above, or just with 'd.shadedmap' +
d.out.file if the only transparency you want is between 2 raster
maps. (but it sounds like you want it for vectors..)

Hamish