[GRASS-dev] how to do g.region n=n+(defined by user input option) in a python script?
Glynn Clements
glynn at gclements.plus.com
Thu May 8 08:45:39 PDT 2014
Helmut Kudrnovsky wrote:
> regext = options['region_extension']
> 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'
"regext" will be a string; you need to use e.g.
regext = float(regext)
before you can do arithmetic with it.
Also, unless the purpose of the script is to modify the region for
subsequent commands, either use use_temp_region() to localise any
changes to the script.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list