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
howtos:how_to_calculate_an_area-weighted_average_in_grass [2026-10-23 01:32 am] – hchohowtos:how_to_calculate_an_area-weighted_average_in_grass [2026-10-23 01:38 am] (current) – hcho
Line 8: Line 8:
 r.to.vect rast_val out=vect_val type=area r.to.vect rast_val out=vect_val type=area
  
-# calculate the cell areas of the area vector+# calculate the areas of the area vector polygons
 v.to.db vect_val op=area col=area_m2 v.to.db vect_val op=area col=area_m2
  
Line 14: Line 14:
 v.overlay ainput=vect_val binput=vect_area oper=or output=vect_val_area v.overlay ainput=vect_val binput=vect_area oper=or output=vect_val_area
  
-# add and populate a new column with the area-weighted average+# 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 \ v.db.update vect_area col=avg_val \
   qcol="(select sum(a_value*a_area_m2)/sum(a_area_m2) from vect_val_area \   qcol="(select sum(a_value*a_area_m2)/sum(a_area_m2) from vect_val_area \
          where vect_val_area.b_cat=vect_area.cat group by b_cat)"          where vect_val_area.b_cat=vect_area.cat group by b_cat)"
 </code> </code>
howtos/how_to_calculate_an_area-weighted_average_in_grass.txt · Last modified: by hcho

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki