[GRASS-user] Getting statistical values (r.univar) via python

Johannes Radinger JRadinger at gmx.at
Fri May 25 07:12:39 EDT 2012


Hi,

I am trying to get statistical values for a raster map in a python script.
What I am doing so far is using r.univar (e.g. for the nc-dataset):

grass.read_command("r.univar", map ="elevation")

but how to get e.g the mean value as float? I thought of two
options: 

1) either indexing like
float(grass.read_command("r.univar", map ="elevation")[x:y])

2) or splitting the string into lines and then at the ":"

The problem with the first method, although quite easy, is that
the indexing numbers [x:y] actually depend on the map (different
decimal value lengths). Thus it is probably not possible to use
the first approach in a automatized way e.g. loop.
I haven't tried the second approach as I am not that familiar with
string splitting yet, but any hint is appreciated.

In the Wiki (http://grass.osgeo.org/wiki/GRASS_Python_Scripting_Library#Using_output_from_GRASS_modules_in_the_script) I found an example for grass.raster_info
but that does not provide e.g. a mean value.

Any suggestions or is there even an other method?

/Johannes


-- 
NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone!                                  
Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a


More information about the grass-user mailing list