HydroCS Wiki

Pioneering Hydrologic Computational Science

User Tools

Site Tools


howtos:how_to_calculate_an_area-weighted_average_in_grass

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
howtos:how_to_calculate_an_area-weighted_average_in_grass [2026-10-23 12:50 am] – hchohowtos:how_to_calculate_an_area-weighted_average_in_grass [2026-11-07 03:12 pm] (current) – hcho
Line 3: Line 3:
 <code bash> <code bash>
 # set the computational region to the value raster # set the computational region to the value raster
-g.region rast=rast_val -ap+g.region rast=val_rast -ap
  
 # convert the value raster to area vector # convert the value raster to area vector
-r.to.vect rast_val out=vect_val type=area+r.to.vect val_rast out=val_vect type=area
  
-# OR-overlay the value vector and area vector +# overlay the value vector OR the area vector 
-v.overlay ainput=vect_val binput=vect_area oper=or output=vect_val_area+v.overlay ainput=val_vect binput=area_vect oper=or output=val_area_vect
  
-# calculate and validate the area-weighted area value grouped by area vector; +# calculate the areas of the value-OR-area vector polygons 
-# this command doesn't update anything +v.to.db val_area_vect op=area col=area_m2
-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 +# add a new column for the area-weighted average 
-v.db.update vect_area col=avg_val \ +v.db.addcolumn area_vect col="avg_val double" 
-  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)"+# populate the new column with the area-weighted average 
 +v.db.update area_vect col=avg_val \ 
 +  qcol="(select sum(a_value*area_m2)/sum(area_m2) from val_area_vect \ 
 +         where val_area_vect.b_cat=area_vect.cat group by b_cat)"
 </code> </code>
howtos/how_to_calculate_an_area-weighted_average_in_grass.1792716628.txt.gz · Last modified: by hcho

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki