[GRASS-dev] how to do g.region n=n+(defined by user input option) in a python script?

Helmut Kudrnovsky hellik at web.de
Thu May 8 04:39:42 PDT 2014


hi,

I'm trying to understand how to use g.region n=n+x s=s-x e=e+x w=w-x in a
python script, where x is a user option.

some code snippets:

#%option
#% key: region_extension
#% type: double
#% key_desc: float
#% description: region extension
#% required : no
#% answer: 5000
#%end

[...]

    regext = options['region_extension']

[...]

    grass.run_command('g.region', n = n+regext,
                                     s = s-regext,
                                     e = e+regext,
                                     w = w-regext)

doesn't work with following error:

Traceback (most recent call last):
  File "C:\Users\myricaria\AppData\Roaming\GRASS7\addons\scr
ipts\v.habitat.dem.py", line 202, in <module>
    sys.exit(main())
  File "C:\Users\myricaria\AppData\Roaming\GRASS7\addons\scr
ipts\v.habitat.dem.py", line 159, in main
    grass.run_command('g.region', n = n+regext,
NameError: global name 'n' is not defined

with 
    current_region = grass.region()
n = current_region["n"]
s = current_region["s"]
e = current_region["e"]
w = current_region["w"]

it could be defined, but then it says

Traceback (most recent call last):
  File "C:\Users\myricaria\AppData\Roaming\GRASS7\addons\scr
ipts\v.habitat.dem.py", line 202, in <module>
    sys.exit(main())
  File "C:\Users\myricaria\AppData\Roaming\GRASS7\addons\scr
ipts\v.habitat.dem.py", line 159, in main
    grass.run_command('g.region', n = n+regext,
TypeError: unsupported operand type(s) for +: 'float' and
'str'

any ideas/pointers?

thanks.



-----
best regards
Helmut
--
View this message in context: http://osgeo-org.1560.x6.nabble.com/how-to-do-g-region-n-n-defined-by-user-input-option-in-a-python-script-tp5139216.html
Sent from the Grass - Dev mailing list archive at Nabble.com.


More information about the grass-dev mailing list