Explorar el Código

grass.py: vector_columns() returns directory instead of list

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@34883 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa hace 16 años
padre
commit
fdd08a7e1b

+ 4 - 3
lib/python/grass.py

@@ -490,15 +490,16 @@ def db_connection():
 # 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

+ 1 - 1
scripts/v.db.dropcol/v.db.dropcol.py

@@ -77,7 +77,7 @@ def main():
     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":

+ 1 - 1
scripts/v.db.join/v.db.join.py

@@ -86,7 +86,7 @@ def main():
     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']

+ 4 - 7
scripts/v.db.update/v.db.update.py

@@ -85,13 +85,10 @@ def main():
     driver = f[4]
 
     # checking column types
-    coltype = None
-    for f in grass.vector_columns(map, layer):
-	if f[1] == column:
-	    coltype = f[0]
-
-    if not coltype:
-	grass.fatal('column <%s> not found' % column)
+    try:
+        coltype = grass.vector_columns(map, layer)[column]
+    except KeyError:
+	grass.fatal('Column <%s> not found' % column)
 
     if qcolumn:
 	if value:

+ 6 - 6
scripts/v.dissolve/v.dissolve.py

@@ -80,12 +80,12 @@ def main():
 	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)

+ 1 - 1
scripts/v.rast.stats/v.rast.stats.py

@@ -194,7 +194,7 @@ def main():
 	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.")

+ 1 - 1
scripts/v.report/v.report.py

@@ -84,7 +84,7 @@ def main():
     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']
 

+ 1 - 1
scripts/v.to.3d/v.to.3d.py

@@ -96,7 +96,7 @@ def main():
             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)