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 the areas of the value-OR-area vector polygons v.to.db vect_val_area op=area col=area_m2 # add a new column for the area-weighted average v.db.addcolumn vect_area col="avg_val double" # populate the new column with the area-weighted average v.db.update vect_area col=avg_val \ qcol="(select sum(a_value*area_m2)/sum(area_m2) 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.1794009794.txt.gz · Last modified: by hcho