v.greedycolors works best if areas have unique categories. If multiple areas have the same category, the corresponding network of neighboring areas can become fairly complex, resulting in a larger number of greedy colors. If the purpose is to assign different colors to neighboring areas, irrespective of their category values, unique category values need to be assigned first, e.g. to a new layer with v.category.
There is always at least one optimal solution for greedy colors, using as few colors as possible. However, it is usually computationally intensive and not practical to search for an optimal solution. Therefore a good solution is aproximated by ordering the areas first, before assigning greedy colors. Here, the areas with the least neighbors are processed first.
Make a copy of the data:
g.copy vect=boundary_county,my_boundary_county
v.greedycolors map=my_boundary_county
db.select sql="select greedyclr,count(greedyclr) from my_boundary_county group by greedyclr"
greedyclr|count(greedyclr) 1|262 2|351 3|302 4|11
Assign RGB colors:
v.db.addcolumn map=my_boundary_county column="GRASSRGB varchar(11)" v.db.update map=my_boundary_county column=GRASSRGB value="127:201:127" where="greedyclr = 1" v.db.update map=my_boundary_county column=GRASSRGB value="190:174:212" where="greedyclr = 2" v.db.update map=my_boundary_county column=GRASSRGB value="253:192:134" where="greedyclr = 3" v.db.update map=my_boundary_county column=GRASSRGB value="255:255:153" where="greedyclr = 4"
Available at: v.greedycolors source code (history)
Latest change: Thursday Mar 20 21:36:57 2025 in commit: 7286ecf7af235bfd089fb9b1b82fb383cf95f3fc
Main index | Vector index | Topics index | Keywords index | Graphical index | Full index
© 2003-2025 GRASS Development Team, GRASS GIS 8.4.2dev Reference Manual