[GRASS-SVN] r46484 - grass/trunk/scripts/v.colors

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jun 1 09:46:50 EDT 2011


Author: mmetz
Date: 2011-06-01 06:46:50 -0700 (Wed, 01 Jun 2011)
New Revision: 46484

Modified:
   grass/trunk/scripts/v.colors/v.colors.py
Log:
various fixes

Modified: grass/trunk/scripts/v.colors/v.colors.py
===================================================================
--- grass/trunk/scripts/v.colors/v.colors.py	2011-06-01 12:42:07 UTC (rev 46483)
+++ grass/trunk/scripts/v.colors/v.colors.py	2011-06-01 13:46:50 UTC (rev 46484)
@@ -180,21 +180,21 @@
     cols = grass.vector_columns(map, layer = layer)
     if column not in cols:
 	grass.fatal(_("Column <%s> not found") % column)
-    ncolumn_type = cols[column]
+    ncolumn_type = cols[column]['type']
     if ncolumn_type not in ["INTEGER", "DOUBLE PRECISION"]:
-	grass.fatal(_("Column <%s> is not numeric") % column)
+	grass.fatal(_("Column <%s> is not numeric but %s") % (column, ncolumn_type))
 
     #g.message "column <$GIS_OPT_COLUMN> is type [$NCOLUMN_TYPE]"
 
     # check if GRASSRGB column exists, make it if it doesn't
-    table = grass.vector_db(map)[layer]['table']
+    table = grass.vector_db(map)[int(layer)]['table']
     if rgb_column not in cols:
         # RGB Column not found, create it
 	grass.message(_("Creating column <%s> ...") % rgb_column)
 	if 0 != grass.run_command('v.db.addcolumn', map = map, layer = layer, column = "%s varchar(11)" % rgb_column):
 	    grass.fatal(_("Creating color column"))
     else:
-	column_type = cols[rgb_column]
+	column_type = cols[rgb_column]['type']
 	if column_type not in ["CHARACTER", "TEXT"]:
 	    grass.fatal(_("Column <%s> is not of compatible type (found %s)") % (rgb_column, column_type))
 	else:
@@ -202,7 +202,7 @@
 	    if num_chars < 11:
 		grass.fatal(_("Color column <%s> is not wide enough (needs 11 characters)"), rgb_column)
 
-    cvals = grass.vector_db_select(map, layer = layer, column = column)['values'].values()
+    cvals = grass.vector_db_select(map, layer = int(layer), columns = column)['values'].values()
 
     # find data range
     if range:
@@ -220,7 +220,7 @@
 	grass.fatal(_("Scanning data range"))
 
     # setup internal region
-    use_temp_region()
+    grass.use_temp_region()
     grass.run_command('g.region', rows = 2, cols = 2)
 
     tmp_colr = "tmp_colr_%d" % pid
@@ -255,7 +255,7 @@
     f = open(tmp, 'w')
     p = grass.feed_command('r.what.color', flags = 'i', input = tmp_colr, stdout = f)
     lastval = None
-    for v in sorted(cvals):
+    for v in sorted(vals):
 	if v == lastval:
 	    continue
 	p.stdin.write('%f\n' % v)
@@ -269,12 +269,12 @@
     t = string.Template("UPDATE $table SET $rgb_column = '$colr' WHERE $column = $value;\n")
     found = 0
     for line in fi:
-	[value, colr] = line.split(':')
+	[value, colr] = line.split(': ')
 	colr = colr.strip()
 	if len(colr.split(':')) != 3:
 	    continue
 	#grass.debug('LINE=[%s]' % line)
-	fo.write(t.substitute(table = table, rgb_column = rgb_column, colr = colr, value = value))
+	fo.write(t.substitute(table = table, rgb_column = rgb_column, colr = colr, column = column, value = value))
 	found += 1
     fi.close()
     fo.close()
@@ -301,8 +301,6 @@
 			  description = "generated by v.colors using r.mapcalc")
 	grass.run_command('r.support', map = vcolors,
 			  history = "RGB saved into <%s> using <%s%s%s>" % (rgb_column, color, raster, rules))
-    else:
-	grass.run_command('g.remove', rast = tmp_colr, quiet = True)
 
     #v.db.dropcolumn map=vcol_test col=GRASSRGB
     #d.vect -a vcol_test icon=basic/circle color=none size=8



More information about the grass-commit mailing list