[GRASS-user] Calculate raster statistics for each polygon

Martin Wegmann martin.wegmann at uni-wuerzburg.de
Fri Aug 6 04:30:15 EDT 2010


Hello,

which GRASS version are you using and on which plattform?

I did it with GRASS 6.4.0RC6 on Linux using the example GRASS dataset and it 
worked without problems:

v.rast.stats -e vector=geology at PERMANENT layer=1 raster=elevation at PERMANENT 
colprefix=new_ percentile=90 

and the new attribute table when querying the vector file looks like this:
cat : 270
onemap_pro : 333074592
PERIMETER : 191354.515625
GEOL250_ : 271
GEOL250_ID : 270
GEO_NAME : CZig
SHAPE_area : 333074608.99
SHAPE_len : 191354.519722
new__n : 24
new__min : 106.708168
new__max : 108.974335
new__range : 2.266167
new__mean : 107.466569
new__stdde : 0.653831
new__varia : 0.427495
new__cf_va : 0.608404
new__sum : 2579.197662
new__first : 106.772
new__media : 107.506
new__third : 107.803
new__per90 : 108.416

regards, Martin


On Freitag, 6. August 2010 10:22:10 katrin eggert wrote:
> Hi
> Thanks Martin but It's not working. With the following command
> v.rast.stats -c -e --verbose vector=seg1 at PERMANENT
> raster=SEG.1 at PERMANENTcolprefix=stat
> 
> I'm getting this error:
> Adding columns ' stat_n INTEGER, stat_min DOUBLE PRECISION, stat_max DOUBLE
> PRECISION, stat_range DOUBLE PRECISION, stat_mean DOUBLE PRECISION,
> stat_stdde DOUBLE PRECISION, stat_varia DOUBLE PRECISION, stat_cf_va DOUBLE
> PRECISION, stat_sum DOUBLE PRECISION, stat_first DOUBLE PRECISION,
> stat_media DOUBLE PRECISION, stat_third DOUBLE PRECISION, stat_per90 DOUBLE
> PRECISION'
> C:/GRASS6/scripts/v.rast.stats: line 268: v.db.addcol:
> command not found
> ERROR: Cannot continue (problem adding columns).
> 
> Why am I getting this? Or, what I have to do before I run v.rast.stat?
> Thanks
> Kat
> 
> 
> 
> 2010/8/5 Martin Wegmann <martin.wegmann at uni-wuerzburg.de>
> 
> > Hello,
> > 
> > I think v.rast.stats is what you are looking for
> > 
> > http://grass.itc.it/gdp/html_grass64/v.rast.stats.html
> > 
> > regards, Martin
> > 
> > On Donnerstag, 5. August 2010 18:25:37 katrin eggert wrote:
> > > Hello
> > > 
> > > I have polygon layer which divides my image into several areas all
> > > contiguous. With the same size, I have a raster image. I want to:
> > > 
> > > - calculate the most frequent value of the raster inside each polygon;
> > > 
> > > - the maximum and minimum value inside each polygon
> > > 
> > > How can this be done in GRASS?
> > > 
> > > 
> > > Thanks
> > > 
> > > Katrin



More information about the grass-user mailing list