howtos:how_to_calculate_an_area-weighted_average_in_grass
This is an old revision of the document!
How to calculate an area-weighted average in GRASS
# set the computational region to the value raster g.region rast=rast_val -ap # convert the value raster to area vector r.to.vect rast_val out=vect_val type=area # overlay the value vector OR the area vector v.overlay ainput=vect_val binput=vect_area oper=or output=vect_val_area # calculate and validate the area-weighted area value grouped by area vector; # this command doesn't update anything v.db.select vect_val_area col="b_cat,sum(a_value*a_area)/sum(a_area)" \ group=b_cat # add and populate a new column with the area-weighted average v.db.update vect_area col=avg_val \ qcol="(select sum(a_value*a_area)/sum(a_area) from vect_val_area \ where vect_val_area.b_cat=vect_area.cat group by b_cat)"
howtos/how_to_calculate_an_area-weighted_average_in_grass.1792716659.txt.gz · Last modified: by hcho