[GRASS-user] script in python

Moritz Lennert mlennert at club.worldonline.be
Mon Dec 1 10:10:18 EST 2008


On 01/12/08 15:55, Gabriele Nolè wrote:
> 
> Moritz Lennert-2 wrote:
>> On 01/12/08 15:23, Gabriele Nolè wrote:
>>> Hi Jose.	
>>> I changed the code by trying different solutions, such as:
>>> ------------------------------------------------------------------------------------------
>>> def main():
>>> 	vect1 = options['vect_1']
>>> 	vect2 = options['vect_2']
>>> 	vect3 = options['vect_3']
>>> 	
>>>        
>>> vbuffer=subprocess.Popen('v.buffer','input=vect_1','output=buffer_200m','buffer=200')
>>> 	retcode=vbuffer.wait()  
>>> 	 
>>>       # Then I also tried with another command (v.db.addcol):
>>>       #import subprocess
>>>      
>>> #vaddcol=subprocess.Popen('v.db.addcol','map=vect_1','columns=prova','VARCHAR(15)')
>>
>> The parameter for v.db.addcol is columns='prova varchar(15)'. I don't 
>> think you can split that up into two parameters. Shouldn't this be:
>>
>> vaddcol=subprocess.Popen('v.db.addcol','map=vect_1','columns=prova 
>> VARCHAR(15)')
>>
>> ?
>> (don't know if the white space is allowed as such or whether you need to 
>> quote the entire parameter as "prova VARCHAR(15)")
>>
>> Moritz
>>
> 	
> Yes, I have tried in this way but not right (with 'columns=prova
> VARCHAR(15)').
> Now I have also tried to remove white space but ... nothing

As Glynn has already said: check the existing scripts in trunk[1]. E.g. 
in v.rast.stats.py:

             if i == "n":
                 coltype = "INTEGER"
             else:
                 coltype = "DOUBLE PRECISION"
             addcols.append(currcolumn + ' ' + coltype)

     if addcols:
         grass.verbose("Adding columns <%s>" % addcols)
         if grass.run_command('v.db.addcol', map = vector, columns = 
addcols) != 0:

Moritz

[1] http://trac.osgeo.org/grass/browser/grass/trunk/scripts


More information about the grass-user mailing list