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 01:38 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
- +
-# calculate the areas of the area vector polygons +
-v.to.db vect_val op=area col=area_m2+
  
 # overlay the value vector OR the 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 the areas of the value-OR-area vector polygons 
 +v.to.db val_area_vect op=area col=area_m2
  
 # add a new column for the area-weighted average # add a new column for the area-weighted average
-v.db.addcolumn vect_area col="avg_val double"+v.db.addcolumn area_vect col="avg_val double"
  
 # populate the new column with the area-weighted average # populate the new column with the area-weighted average
-v.db.update vect_area col=avg_val \ +v.db.update area_vect col=avg_val \ 
-  qcol="(select sum(a_value*a_area_m2)/sum(a_area_m2) from vect_val_area \ +  qcol="(select sum(a_value*area_m2)/sum(area_m2) from val_area_vect \ 
-         where vect_val_area.b_cat=vect_area.cat group by b_cat)"+         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.1792719488.txt.gz · Last modified: by hcho

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki