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