v.colors2
Sets color rules for features in a vector map using a numeric attribute column.
v.colors2 [-sn] map=name [layer=string] column=name [rgb_column=name] [range=min,max] [color=string] [raster=name] [rules=name] [--verbose] [--quiet] [--qq] [--ui]
Example:
v.colors2 map=name column=name
grass.script.run_command("v.colors2", map, layer="1", column, rgb_column="GRASSRGB", range=None, color=None, raster=None, rules=None, flags=None, verbose=False, quiet=False, superquiet=False)
Example:
gs.run_command("v.colors2", map="name", column="name")
Parameters
map=name [required]
Name of vector map
Or data source for direct OGR access
layer=string
Layer number or name
Vector features can have category values in different layers. This number determines which layer to use. When used with direct OGR access this is the layer name.
Default: 1
column=name [required]
Name of attribute column containing numeric data
rgb_column=name
Name of color column to populate with RGB values
Default: GRASSRGB
range=min,max
Manually set range (min,max)
color=string
Type of color table
Allowed values: aspect, aspectcolr, bcyr, bgyr, byg, byr, celsius, corine, curvature, differences, elevation, etopo2, evi, gdd, grey, grey1.0, grey255, grey.eq, grey.log, gyr, ndvi, population, precipitation, rainbow, ramp, random, ryb, ryg, sepia, slope, srtm, terrain, wave
raster=name
Name of raster map from which to copy color table
rules=name
Name of file containing rules
-s
Save placeholder raster map for use with d.legend
-n
Invert colors
--help
Print usage summary
--verbose
Verbose module output
--quiet
Quiet module output
--qq
Very quiet module output
--ui
Force launching GUI dialog
map : str, required
Name of vector map
Or data source for direct OGR access
Used as: input, vector, name
layer : str, optional
Layer number or name
Vector features can have category values in different layers. This number determines which layer to use. When used with direct OGR access this is the layer name.
Used as: input, layer
Default: 1
column : str, required
Name of attribute column containing numeric data
Used as: input, dbcolumn, name
rgb_column : str, optional
Name of color column to populate with RGB values
Used as: input, dbcolumn, name
Default: GRASSRGB
range : tuple[float, float] | list[float] | str, optional
Manually set range (min,max)
Used as: min,max
color : str, optional
Type of color table
Used as: string
Allowed values: aspect, aspectcolr, bcyr, bgyr, byg, byr, celsius, corine, curvature, differences, elevation, etopo2, evi, gdd, grey, grey1.0, grey255, grey.eq, grey.log, gyr, ndvi, population, precipitation, rainbow, ramp, random, ryb, ryg, sepia, slope, srtm, terrain, wave
raster : str, optional
Name of raster map from which to copy color table
Used as: input, raster, name
rules : str, optional
Name of file containing rules
Used as: input, file, name
flags : str, optional
Allowed values: s, n
s
Save placeholder raster map for use with d.legend
n
Invert colors
verbose: bool, optional
Verbose module output
Default: False
quiet: bool, optional
Quiet module output
Default: False
superquiet: bool, optional
Very quiet module output
Default: False
DESCRIPTION
v.colors is much like r.colors, but may be used for vector maps. You
give it a vector map and numeric data column, together with color rules
like you would do for a raster. It creates a new column in the database
with R:G:B values suitable for use with 'd.vect -a
'.
How it works: it creates a dummy raster map with the same data range as the vector's column then runs r.colors for that temporary map. It then uses r.what.colors for each value found by v.db.select and uploads it a new column in the vector map's attribute database.
It is planned that this script will be replaced with a C display module which renders thematic vector maps directly instead requiring the overhead of saving the colors into the DB.
If the target column name given by the rgb_column option does not
exist, it will be created. The default name is "GRASSRGB
".
EXAMPLES
Create a random sample point map, query raster map values for those points, and colorize output.
# Spearfish dataset
g.region -d
v.random out=rand5k_elev n=5000
v.db.addtable map=rand5k_elev column='elevation double precision'
v.what.rast vector=rand5k_elev raster=elevation.10m column=elevation
v.colors map=rand5k_elev column=elevation color=bcyr
# display colorized points map
d.mon x0
d.vect -a rand5k_elev
Colorizing the roads map in Spearfish:
g.copy vector=roads,myroads
echo "1 red
2 yellow
3 orange
4 black
5 grey" > colors.txt
v.colors myroads column=cat rules=colors.txt
# display colorized roads map
d.mon x0
d.vect -a myroads
Colorizing a TIN (polygons) generated by v.delaunay:
# new columns for x,y,z of centroids
v.db.addtable map=tin \
columns="east double precision, north double precision, height double precision, GRASSRGB varchar(11)"
# transfer geometry for colorizing (we need the centroid height)
v.to.db tin option=coor columns="east,north,height"
v.db.select tin
v.colors tin column=height rgb_column=GRASSRGB color=rainbow
# display colorized triangles
d.mon x0
d.vect -a tin
SEE ALSO
d.vect, r.colors, r.colors.stddev, r.what.color, v.db.addcolumn, v.db.select, db.execute
AUTHOR
Hamish Bowman
Dunedin, New Zealand
SOURCE CODE
Available at: v.colors2 source code
(history)
Latest change: Thursday Feb 20 13:02:26 2025 in commit 53de819