[GRASS-user] script in python

Gabriele Nolè gis.gn at libero.it
Tue Dec 2 03:38:32 EST 2008


Glynn thanks. 	
Now go better.
I added

#%option
#% key: buff
#% type: string
#% description: misura buffer (in metri)
#% required : yes
#%end

buff1 = options['buff']	
	
	grass.run_command('v.buffer', input = vect1, output = "buffer", buffer =
buff1) 




> Apart from anything else, it's hard to write shell scripts which work
> reliably on Windows. More generally, it's hard to write anything other
> than simple scripts using bash (or any Bourne shell).
> 
> The intention is that it will be possible to run all of GRASS on
> Windows without requiring a shell or Unix utilities.
> 
I want to learn ..... to get the best GRASS :-)
Now continuing with the script, but the script does not finish ever (I also
tried with grass.exec_command .... and I inserted at the end sys.exit (0) as
I saw in your scripts).

I'm happy for the evolution of GRASS 7. I sometimes are forced to use GRASS
on windows and use all the scripts in pyhton would be great.

Grazie 
Ciao
Gabriele


Glynn Clements wrote:
> 
> 
> Gabriele Nolè wrote:
> 
>> I use ubuntu 8.10 and grass64 svn
>> I made the changes based on your claims.
>> This is my code: 
>> -------------------------------------------------------------------------------------
>> def main():
>> 	# con = assegno le variabili
>> 	vect1 = options['vect_1']
>> 	vect2 = options['vect_2']
>> 	vect3 = options['vect_3']	
>> 
>> 	grass.run_command('v.buffer', input = vect_1, output = buffer_200m,
>> buffer = 200)
>> 
>> if __name__ == "__main__":
>>             options, flags = grass.parser()
>>             main()
>> ---------------------------------------------------------------------------------------------
>> But  if __name__ == "__main__": etc      ...... what is your job? 
> 
> __name__ contains the name of the current module. For a Python script
> which is being executed (rather than "import"ed), the name is "__main__".
> 
> The check allows scripts to contain code which is only executed if the
> script is being executed directly.
> 
>> Unfortunately, I made several attempts, but I have an error: 
> 
>>     grass.run_command('v.buffer', input = vect_1, output = buffer_200m,
>> buffer = 200)
> 
>> NameError: global name 'vect_1' is not defined
> 
> The above code assigns the variable "vect1":
> 
>> 	vect1 = options['vect_1']
> 
> but references "vect_1":
> 
>> 	grass.run_command('v.buffer', input = vect_1, output = buffer_200m,
>> buffer = 200)
> 
> The two must match.
> 
>> I do not know how "to treat" the output of the v.buffer (in this case,
>> buffer_200m).
> 
> As buffer_200m is a literal string, not a variable, it needs to be
> quoted, e.g.:
> 
> 	grass.run_command('v.buffer', input = vect1, output = "buffer_200m",
> buffer = 200)
> 
>> With grass 7 will work scripts in bash?
> 
> You can script GRASS commands in any language, but we intend to
> convert all of the shell scripts which are included in GRASS to Python
> for GRASS 7.
> 
> Apart from anything else, it's hard to write shell scripts which work
> reliably on Windows. More generally, it's hard to write anything other
> than simple scripts using bash (or any Bourne shell).
> 
> The intention is that it will be possible to run all of GRASS on
> Windows without requiring a shell or Unix utilities.
> 
> -- 
> Glynn Clements <glynn a gclements.plus.com>
> _______________________________________________
> grass-user mailing list
> grass-user a lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-user
> 
> 

-- 
View this message in context: http://www.nabble.com/script-in-python-tp20758838p20788071.html
Sent from the Grass - Users mailing list archive at Nabble.com.



More information about the grass-user mailing list