[GRASS-SVN] r36072 - grass-addons/raster/r.univar2.zonal

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Feb 24 01:25:57 EST 2009


Author: hamish
Date: 2009-02-24 01:25:57 -0500 (Tue, 24 Feb 2009)
New Revision: 36072

Modified:
   grass-addons/raster/r.univar2.zonal/r.univar.html
Log:
working example using SQL command file | db.execute added

Modified: grass-addons/raster/r.univar2.zonal/r.univar.html
===================================================================
--- grass-addons/raster/r.univar2.zonal/r.univar.html	2009-02-24 05:16:33 UTC (rev 36071)
+++ grass-addons/raster/r.univar2.zonal/r.univar.html	2009-02-24 06:25:57 UTC (rev 36072)
@@ -40,9 +40,29 @@
 
 #### preform analysis
 r.univar.zonal -t in=elevation.10m zones=fields.10m | \
-  cut -f1,2,5,6,8 -d'|' > fields_stats.txt
+  cut -f1,5,6,8 -d'|' > fields_stats.txt
 
 
+#### populate vector DB with stats
+
+# create working copy of vector map
+g.copy vect=fields,fields_stats
+
+# create new attribute columns to hold output
+v.db.addcol map=fields_stats \
+  columns='mean_elev DOUBLE PRECISION, min_elev DOUBLE PRECISION, max_elev DOUBLE PRECISION'
+
+# create SQL command file, and execute it
+sed -e '1d' fields_stats.txt | awk -F'|' \
+  '{print "UPDATE fields_stats SET min_elev = "$2", max_elev = "$3", \
+  mean_elev = "$4" WHERE cat = "$1";"}' \
+   > fields_stats_sqlcmd.txt
+
+db.execute input=fields_stats_sqlcmd.txt
+<!--
+
+###### alternate method with db.in.ogr:  (needs work) ######
+
 #### convert text file table to a database table
 # not safe for commas in the label
 tr '|' ',' < fields_stats.txt > fields_stats.csv
@@ -71,6 +91,10 @@
 ## how to automatically collate by key column, ie copy between tables?
 ## SELECT INTO? JOIN?
 echo "INSERT INTO fields_stats (mean_elev,min_elev,max_elev) SELECT mean,min,max FROM fields_data" | db.execute
+-->
+
+#### view completed table
+v.db.select fields_stats
 </pre></div>
 
 



More information about the grass-commit mailing list