[GRASS-dev] Python Scripting
W. Chris Carleton
w_chris_carleton at hotmail.com
Tue Jul 15 13:43:20 EDT 2008
I'm trying to automate some modules in GRASS 6.3.2 using Python scripts
and g.parser. I've had a look at the examples in /Scripts, but I'm
having some trouble. I want to pass arguments to a GRASS module by
iterating over a list of values. Here's what I have;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#copied the g.parser headers and appropriately modified so that a GUI
#with the correct OPT fields does come up, but script fails when run
import os
import sys
#read cat file export (from v.category) and create a list of cat values
a=open("/home/wchris/Desktop/test.txt")
b=[]
for line in a:
b.append(line)
#generate the catlist and clear \n from the input file
catlist=[]
for i in b:
catlist.append(i[:-1])
#call GRASS module and iterate over catlist using it as input for
#v.extract argument list
for i in catlist:
list=i
v.extract input="$GIS_OPT_INPUT" output="$GIS_OPT_OUTPUT""_"i \
type="point" layer=1 new=-1 list=i
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I've also looked into some shell scripting that was mentioned in a
previous mailing at http://www.tldp.org/LDP/abs/html/loops1.html so
apparently iterating over a list and passing those elements as arguments
to a function is possible, but I'm lost. I'm also fairly new to Python.
Thanks for the help if you can offer any,
Chris
More information about the grass-dev
mailing list