[GRASS-SVN] r34883 - in grass/trunk: lib/python scripts/v.db.dropcol scripts/v.db.join scripts/v.db.update scripts/v.dissolve scripts/v.rast.stats scripts/v.report scripts/v.to.3d

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Dec 14 15:41:19 EST 2008


Author: martinl
Date: 2008-12-14 15:41:19 -0500 (Sun, 14 Dec 2008)
New Revision: 34883

Modified:
   grass/trunk/lib/python/grass.py
   grass/trunk/scripts/v.db.dropcol/v.db.dropcol.py
   grass/trunk/scripts/v.db.join/v.db.join.py
   grass/trunk/scripts/v.db.update/v.db.update.py
   grass/trunk/scripts/v.dissolve/v.dissolve.py
   grass/trunk/scripts/v.rast.stats/v.rast.stats.py
   grass/trunk/scripts/v.report/v.report.py
   grass/trunk/scripts/v.to.3d/v.to.3d.py
Log:
grass.py: vector_columns() returns directory instead of list


Modified: grass/trunk/lib/python/grass.py
===================================================================
--- grass/trunk/lib/python/grass.py	2008-12-14 20:29:50 UTC (rev 34882)
+++ grass/trunk/lib/python/grass.py	2008-12-14 20:41:19 UTC (rev 34883)
@@ -490,15 +490,16 @@
 # run "v.info -c ..." and parse output
 
 def vector_columns(map, layer = None, **args):
-    """Return the list of columns for the database table connected to
+    """Return the directory of columns for the database table connected to
     a vector map (interface to `v.info -c').
     """
     s = read_command('v.info', flags = 'c', map = map, layer = layer, quiet = True, **args)
-    result = []
+    result = {}
     for line in s.splitlines():
 	f = line.split('|')
 	if len(f) == 2:
-	    result.append(f)
+            result[f[1]] = f[0]
+    
     return result
 
 # add vector history

Modified: grass/trunk/scripts/v.db.dropcol/v.db.dropcol.py
===================================================================
--- grass/trunk/scripts/v.db.dropcol/v.db.dropcol.py	2008-12-14 20:29:50 UTC (rev 34882)
+++ grass/trunk/scripts/v.db.dropcol/v.db.dropcol.py	2008-12-14 20:41:19 UTC (rev 34883)
@@ -77,7 +77,7 @@
     if column == keycol:
 	grass.fatal("Cannot delete <$col> column as it is needed to keep table <%s> connected to the input vector map <%s>" % (table, map))
 
-    if column not in [f[1] for f in grass.vector_columns(map, layer)]:
+    if not grass.vector_columns(map, layer).has_key(column):
 	grass.fatal("Column <%s> not found in table <%s>" % (column, table))
 
     if driver == "sqlite":

Modified: grass/trunk/scripts/v.db.join/v.db.join.py
===================================================================
--- grass/trunk/scripts/v.db.join/v.db.join.py	2008-12-14 20:29:50 UTC (rev 34882)
+++ grass/trunk/scripts/v.db.join/v.db.join.py	2008-12-14 20:41:19 UTC (rev 34883)
@@ -86,7 +86,7 @@
     if not maptable:
 	grass.fatal("There is no table connected to this map. Cannot join any column.")
 
-    if column not in [f[1] for f in grass.vector_columns(map, layer)]:
+    if not grass.vector_columns(map, layer).has_key(column):
 	grass.fatal("Column <%> not found in table <%s> at layer <%s>" % (column, map, layer))
 
     cols = grass.db_describe(otable, driver = driver, database = database)['cols']

Modified: grass/trunk/scripts/v.db.update/v.db.update.py
===================================================================
--- grass/trunk/scripts/v.db.update/v.db.update.py	2008-12-14 20:29:50 UTC (rev 34882)
+++ grass/trunk/scripts/v.db.update/v.db.update.py	2008-12-14 20:41:19 UTC (rev 34883)
@@ -85,14 +85,11 @@
     driver = f[4]
 
     # checking column types
-    coltype = None
-    for f in grass.vector_columns(map, layer):
-	if f[1] == column:
-	    coltype = f[0]
+    try:
+        coltype = grass.vector_columns(map, layer)[column]
+    except KeyError:
+	grass.fatal('Column <%s> not found' % column)
 
-    if not coltype:
-	grass.fatal('column <%s> not found' % column)
-
     if qcolumn:
 	if value:
 	    grass.fatal('value= and qcolumn= are mutually exclusive')

Modified: grass/trunk/scripts/v.dissolve/v.dissolve.py
===================================================================
--- grass/trunk/scripts/v.dissolve/v.dissolve.py	2008-12-14 20:29:50 UTC (rev 34882)
+++ grass/trunk/scripts/v.dissolve/v.dissolve.py	2008-12-14 20:41:19 UTC (rev 34883)
@@ -80,12 +80,12 @@
 	grass.run_command('v.extract', flags = 'd', input = input,
 			  output = output, type = 'area', layer = layer)
     else:
-	coltype = ''
-	for f in grass.vector_columns(map, layer):
-	    if f[1] == column:
-		coltype = f[0]
-
-	if coltype not in ['INTEGER', 'CHARACTER']:
+        try:
+            coltype = grass.vector_columns(map, layer)[column]
+        except KeyError:
+            grass.fatal('Column <%s> not found' % column)
+        
+	if coltype not in ('INTEGER', 'CHARACTER'):
 	    grass.fatal("Key column must be of type integer or string")
 
 	f = grass.vector_db(input, layer)

Modified: grass/trunk/scripts/v.rast.stats/v.rast.stats.py
===================================================================
--- grass/trunk/scripts/v.rast.stats/v.rast.stats.py	2008-12-14 20:29:50 UTC (rev 34882)
+++ grass/trunk/scripts/v.rast.stats/v.rast.stats.py	2008-12-14 20:41:19 UTC (rev 34883)
@@ -194,7 +194,7 @@
 	if dbfdriver:
 	    currcolumn = currcolumn[:10]
 
-	if currcolumn in [f[1] for f in grass.vector_columns(vector, layer)]:
+	if currcolumn in grass.vector_columns(vector, layer).keys():
 	    if not flags['c']:
 		grass.fatal(("Cannot create column <%s> (already present)." % currcolumn) +
 			    "Use -c flag to update values in this column.")

Modified: grass/trunk/scripts/v.report/v.report.py
===================================================================
--- grass/trunk/scripts/v.report/v.report.py	2008-12-14 20:29:50 UTC (rev 34882)
+++ grass/trunk/scripts/v.report/v.report.py	2008-12-14 20:41:19 UTC (rev 34883)
@@ -84,7 +84,7 @@
     table_exists = grass.vector_columns(mapname, layer, stderr = nuldev)
 
     if table_exists:
-	colnames = [f[1] for f in grass.vector_columns(mapname, layer, stderr = nuldev)]
+	colnames = table_exists.keys()
     else:
 	colnames = ['cat']
 

Modified: grass/trunk/scripts/v.to.3d/v.to.3d.py
===================================================================
--- grass/trunk/scripts/v.to.3d/v.to.3d.py	2008-12-14 20:29:50 UTC (rev 34882)
+++ grass/trunk/scripts/v.to.3d/v.to.3d.py	2008-12-14 20:41:19 UTC (rev 34883)
@@ -96,7 +96,7 @@
             grass.fatal("Either 'height' or 'column' parameter have to be used")
         # attribute height, check column type
         try:
-            coltype = grass.vector_columns2(map = input, layer = layer)[column]
+            coltype = grass.vector_columns(map = input, layer = layer)[column]
         except KeyError:
             grass.fatal("Column <%s> not found" % column)
     



More information about the grass-commit mailing list