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

Moritz Lennert mlennert at club.worldonline.be
Fri May 25 07:50:59 EDT 2012


On 25/05/12 13:12, Johannes Radinger wrote:
> 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?

There are probably more elegant ways, but this should work:

float(grass.read_command("r.univar", 
map="elevation").splitlines()[10].split()[4])

Moritz


More information about the grass-user mailing list