[GRASS-SVN] r58728 - grass/trunk/scripts/v.rast.stats

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jan 15 05:18:14 PST 2014


Author: lucadelu
Date: 2014-01-15 05:18:14 -0800 (Wed, 15 Jan 2014)
New Revision: 58728

Modified:
   grass/trunk/scripts/v.rast.stats/v.rast.stats.py
Log:
fix bugs with dbf driver

Modified: grass/trunk/scripts/v.rast.stats/v.rast.stats.py
===================================================================
--- grass/trunk/scripts/v.rast.stats/v.rast.stats.py	2014-01-14 23:15:24 UTC (rev 58727)
+++ grass/trunk/scripts/v.rast.stats/v.rast.stats.py	2014-01-15 13:18:14 UTC (rev 58728)
@@ -175,6 +175,8 @@
     # so colprefix can't be longer than 6 chars with DBF driver
     if dbfdriver:
         colprefix = colprefix[:6]
+        variables_dbf = {}
+        
 
     # do extended stats?
     # by default perccol variable is used only for "variables" variable
@@ -196,6 +198,7 @@
         currcolumn = ("%s_%s" % (colprefix, i))
         if dbfdriver:
             currcolumn = currcolumn[:10]
+            variables_dbf[currcolumn.replace("%s_" % colprefix, '')] = i
 
         colnames.append(currcolumn)
         if currcolumn in grass.vector_columns(vector, layer).keys():
@@ -240,8 +243,8 @@
                  'mean': 7, 'stddev': 9, 'variance': 10, 'coeff_var': 11,
                  'sum': 12, 'first_quartile': 14, 'median': 15,
                  'third_quartile': 16, perccol: 17}
-
-    f.write("BEGIN TRANSACTION\n")
+    if not dbfdriver:
+        f.write("BEGIN TRANSACTION\n")
     for line in p.stdout:
         if first_line:
             first_line = 0
@@ -253,6 +256,8 @@
         first_var = 1
         for colname in colnames:
             variable = colname.replace("%s_" % colprefix, '')
+            if dbfdriver:
+                variable = variables_dbf[variable]
             i = variables[variable]
             value = vars[i]
             # convert nan, +nan, -nan to NULL
@@ -265,8 +270,8 @@
             f.write(" %s=%s" % (colname, value))
 
         f.write(" WHERE %s=%s;\n" % (fi['key'], vars[0]))
-
-    f.write("COMMIT\n")
+    if not dbfdriver:
+        f.write("COMMIT\n")
     p.wait()
     f.close()
 



More information about the grass-commit mailing list