[GRASS-dev] Example python script

Does anybody has an example grass python script that deals with multiple layer input? For example with the input option below with #% multiple set to yes, I would like to create multiple variables, one for each map.

#%option
#% key: input
#% type: string
#% gisprompt: old,cell,raster
#% required: yes
#% multiple: yes
#%end

I am completely new to python, and besides python scripting tutorials and text books, for me using examples is a great way to accelerate the learning process. I have looked into the addon repository and scripts in the GRASS 7 SVN, but haven’t found what I was looking for.

More in general, does anybody have (simple) shell scripts that have now been converted in python scripts? I thought I had seen a page on the grass wiki where code snippets in shell and python were compared, but I can’t find it.

Cheers,

Paulo

On 31/01/13 16:48, Paulo van Breugel wrote:

  Does anybody has an example grass python script that deals with
multiple layer input? For example with the input option below with #%
multiple set to yes, I would like to create multiple variables, one for
each map.

#%option
#% key: input
#% type: string
#% gisprompt: old,cell,raster
#% required: yes
#% multiple: yes
#%end

I am completely new to python, and besides python scripting tutorials
and text books, for me using examples is a great way to accelerate the
learning process. I have looked into the addon repository and scripts in
the GRASS 7 SVN, but haven't found what I was looking for.

More in general, does anybody have (simple) shell scripts that have now
been converted in python scripts? I thought I had seen a page on the
grass wiki where code snippets in shell and python were compared, but I
can't find it.

You can always look at the scripts in grass7. A quick grep through the directory shows:

i.spectral/i.spectral.py
r.buffer.lowmem/r.buffer.lowmem.py
r.in.wms/r.in.wms.py
v.db.addtable/v.db.addtable.py
v.db.univar/v.db.univar.py
v.in.wfs/v.in.wfs.py
v.krige/v.krige.py

Generally, you should be able to do something like this:

rastermaps = input.split(',')

and the access each maps like this:

my_map1 = rastermaps[0]

etc

Moritz

Thanks, I did take a look, but obviously not hard enough (btw, clever trick to use grep… will download the source code so I can use that too).

···

On Thu, Jan 31, 2013 at 5:12 PM, Moritz Lennert <mlennert@club.worldonline.be> wrote:

On 31/01/13 16:48, Paulo van Breugel wrote:

Does anybody has an example grass python script that deals with
multiple layer input? For example with the input option below with #%
multiple set to yes, I would like to create multiple variables, one for
each map.

#%option
#% key: input
#% type: string
#% gisprompt: old,cell,raster
#% required: yes
#% multiple: yes
#%end

I am completely new to python, and besides python scripting tutorials
and text books, for me using examples is a great way to accelerate the
learning process. I have looked into the addon repository and scripts in
the GRASS 7 SVN, but haven’t found what I was looking for.

More in general, does anybody have (simple) shell scripts that have now
been converted in python scripts? I thought I had seen a page on the
grass wiki where code snippets in shell and python were compared, but I
can’t find it.

You can always look at the scripts in grass7. A quick grep through the directory shows:

i.spectral/i.spectral.py
r.buffer.lowmem/r.buffer.lowmem.py
r.in.wms/r.in.wms.py
v.db.addtable/v.db.addtable.py
v.db.univar/v.db.univar.py
v.in.wfs/v.in.wfs.py
v.krige/v.krige.py

Generally, you should be able to do something like this:

rastermaps = input.split(‘,’)

and the access each maps like this:

my_map1 = rastermaps[0]

etc

Moritz