[GRASS-user] pyhton script-how to get the pixel value from r.what
Glynn Clements
glynn at gclements.plus.com
Fri Mar 30 13:09:41 EDT 2012
Adam Dershowitz, Ph.D., P.E. wrote:
> It looks like the grass.read_command returns a string, and you are then trying to do math on it.
> You probably want something like:
>
> import string
> ts_f= grass.read_command("r.what",input=Ts, east_north= "%s,%s" % (eastF,northF))
Note that you can pass lists and tuples directly, e.g.:
ts_f= grass.read_command("r.what", input=Ts, east_north=(eastF,northF))
read_command etc will perform the necessary conversion.
> print "Ts pixel frio=",ts_f
> ts_values=string.split(ts_f,'|')
>
> I am not sure which value you then want. Probably ts_values[3]:
>
> lambda_f=(2.501-(0.00236*(ts_values[3]-273.15)))*1000000
That still doesn't solve the issue of trying to perform arithmetic on
strings; use int() or float() to convert strings to numbers, e.g.
lambda_f=(2.501-(0.00236*(float(ts_values[3])-273.15)))*1000000
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-user
mailing list