Color tables: Difference between revisions

From GRASS-Wiki
Jump to navigation Jump to search
(init)
 
(change link from SVN to github)
 
(46 intermediate revisions by 8 users not shown)
Line 1: Line 1:
''work in progress'' ...
== About ==
Color tables live in <tt>$GISBASE/etc/colors</tt> (see [https://github.com/OSGeo/grass/tree/main/lib/gis/colors github])


Color tables live in <tt>$GISBASE/etc/colors</tt>
== Modules ==
 
* {{cmd|r.colors}} ({{cmd|r.colors}} manual in GRASS 7 has colors tables embedded as well as the GUI dialog)
* {{cmd|r.colors.stddev}} ([http://hamish.bowman.googlepages.com/grass_color_maps samples])
* {{cmd|r.colors.out}}
* {{cmd|r3.colors}}
* {{cmd|r3.colors.out}}
* {{cmd|v.colors}}
* {{cmd|v.colors.out}}


* {{cmd|d.legend}}
* {{cmd|d.legend}}
* {{cmd|r.colors}}
* {{cmd|v.colors}}
* {{cmd|d.colortable}}
* {{cmd|d.colortable}}


* {{cmd|r.colors.stddev}} ([http://hamish.bowman.googlepages.com/grass_color_maps samples])
=== Addons ===
 
* User contributed color rules in the [https://trac.osgeo.org/grass/browser/grass-addons/grass6/raster/r.colors.tools/palettes GRASS Addons repository]
* Convert from [[GMT]] color tables with {{AddonCmd|r.cpt2grass}}
* Use {{AddonCmd|r.colors.quantiles}} to create raster colors rules based on ''n''-quantiles. It uses the [[GRASS_and_Rstat|R and the spgrass6 package]].
* Use {{AddonCmd|r.colors.out_sld}} to export GRASS raster colors rules in OGC SLD template v1.0.0 XML format for Geoserver and the ilk
* Use {{AddonCmd|r.colors.out_vtk}} to export GRASS raster colors rules for use with VTK-based visualization software.
 
== Repositories ==
 
* There is an online colormap repository with many fine [[GMT]] (and many others) gradients at
: http://soliton.vm.bytemark.co.uk/pub/cpt-city/
 
* There are a number of command line tools for working with the GMT .cpt files at
: http://soliton.vm.bytemark.co.uk/pub/jjg/en/code/cptutils/
 
== Examples ==
=== Built in ===
 
The numeric values of following color tables can be found in the [https://svn.osgeo.org/grass/grass/branches/releasebranch_6_4/lib/gis/colors/ here]
 
[[Image:Colortable_aspect.png|center]]
 
 
[[Image:Colortable_aspectcolr.png|center]]
 
 
[[Image:Colortable_bcyr.png|center]]
 
 
[[Image:Colortable_bgyr.png|center]]
 
 
[[Image:Colortable_byg.png|center]]
 
 
[[Image:Colortable_byr.png|center]]
 
 
[[Image:Colortable_celsius.png|center]]
 
 
<!-- [[Image:Colortable_corine.png|center]] -->
[[Image:Colortable_corine_clc.gcolors.png|center]]
 
 
[[Image:Colortable_curvature.png|center]]
 
 
[[Image:Colortable_differences.png|center]]
 
 
[[Image:Colortable_elevation.png|center]]
 
 
[[Image:Colortable_etopo2.png|center]]
 
 
[[Image:Colortable_evi.png|center]]
 
 
[[Image:Colortable_grey.png|center]]
 
 
[[Image:Colortable_grey1.0.png|center]]
 
 
[[Image:Colortable_grey255.png|center]]
 
 
[[Image:Colortable_gyr.png|center]]
 
 
[[Image:Colortable_haxby.png|center]]
 
 
[[Image:Colortable_ndvi.png|center]]
 
 
[[Image:Colortable_population.png|center]]
 
 
[[Image:Colortable_precipitation.png|center]]
 
 
[[Image:Colortable_rainbow.png|center]]
 
 
[[Image:Colortable_ramp.png|center]]
 
 
[[Image:Colortable_ryb.png|center]]
 
 
[[Image:Colortable_ryg.png|center]]
 
 
[[Image:Colortable_sepia.png|center]]
 
 
[[Image:Colortable_slope.png|center]]
 
 
[[Image:Colortable_srtm.png|center]]
 
 
[[Image:Colortable_terrain.png|center]]
 
 
[[Image:Colortable_wave.png|center]]
 
=== Addons ===
 
These user contributions can be found in the [https://trac.osgeo.org/grass/browser/grass-addons/grass6/raster/r.colors.tools/palettes GRASS addons SVN repository]
 
[[Image:Colortable_palette_chl_etc.gcolors.png|center]]
 
 
[[Image:Colortable_palette_sst.gcolors.png|center]]
 
 
[[Image:Colortable_palette_GMT_ocean.gcolors.png|center]]
 
 
[[Image:Colortable_palette_roygbiv.gcolors.png|center]]
 
 
[[Image:Colortable_palette_high_intensity.gcolors.png|center]]
 
 
[[Image:Colortable_palette_low_intensity.gcolors.png|center]]
 
 
* ''The script used to create these thumbnails can be found on the [[Talk:Color_tables|discussion page]].''
 
== Using GRASS color palettes in QGIS ==
 
Most of them can already be found there, you just have to hunt for them. In the raster layer properties window's style tab, select "Singleband pseudocolor" as the type, "Generate new color map", "New color ramp", for ramp type choose "cpt-city", change to the "Sort by Author" tab, and look for "grass". They can also be found in the QGIS section cpt-city's QGIS theme.
 
If there's a new set of color rules which are not in [[QGIS]], you can prepare a .svg palette file for use with QGIS using the following commands. Consider to then open a ticket in the QGIS issue tracker asking them to add it (and attach the file of course to save someone some work :)
 
You will need the [http://soliton.vm.bytemark.co.uk/pub/jjg/en/code/cptutils/ ''cptsvg'' command line tool from cptutils] and the GRASS 6 addon module {{AddonCmd|r.out.gmt|version=64}}.
 
Examples:
<source lang="bash">
g.region n=100 s=0 w=0 e=100 res=1
r.mapcalc "dummy = row()"
r.colors dummy color=roygbiv
r.out.gmt dummy out=roygbiv
rm roygbiv.grd
cptsvg --geometry=300x45 -o roygbiv.svg -v roygbiv.cpt
r.colors dummy rules=~/grass/svn/grass-addons/grass6/raster/r.colors.tools/palettes/palette_sst.gcolors
r.out.gmt dummy out=palette_sst
rm palette_sst.grd
cptsvg --geometry=300x45 -o palette_sst.svg -v palette_sst.cpt
</source>
 
You can then copy the resulting .svg file into <tt>/usr/share/qgis/resources/cpt-city-qgis-min/grass/</tt> on Linux (or <tt>C:\Program&nbsp;Files\QGIS&nbsp;VERSION\apps\qgis\resources\cpt-city-qgis-min\grass\</tt> on MS Windows).
 
Another solution to export raster color tables is to slightly tweak the output of {{Cmd|r.colors.out}}, in order to provide QGIS with a regular color chart source file. It might be handy when dealing with maps produced by {{Cmd|r.composite}}, i.e. unregistered color charts. The example bellow may be adapted to ones needs (here the alpha channel defaults to 255):
<source lang="bash">
r.colors.out map=my_raster rules=~/in.colors
cat in.colors|sed 's/:/,/'g|sed 's/ /,/'g|awk 'BEGIN {FS=",";OFS=","};{print $1,$2,$3,$4,255,$1}'>out.colors
</source>
 
== Loading QGIS color palettes into GRASS ==
 
The GRASS GIS addon module {{AddonCmd|r.cpt2grass|version=7}} can be used after the ''svgx'' command line program from the <tt>cptutils</tt> package, using [[GMT]]'s .cpt color table format as a go-between:
 
<source lang="bash">
svgx --output dkbluered.cpt --type cpt  /usr/share/qgis/resources/cpt-city-qgis-min/h5/dkbluered.svg
r.cpt2grass in=dkbluered.cpt output=dkbluered.gcolors
</source>
 
You can then use the *.gcolors file with the {{Cmd|r.colors}} rules= option (or set the color rules directly from the ''r.cpt2grass'' module).




* Converting from GMT color tables {{AddonCmd|r.cpt2grass}}
[[Category: Documentation]]
[[Category: Colors]]
[[Category: VTK]]
[[Category: QGIS]]

Latest revision as of 19:21, 11 May 2024

About

Color tables live in $GISBASE/etc/colors (see github)

Modules

Addons

Repositories

  • There is an online colormap repository with many fine GMT (and many others) gradients at
http://soliton.vm.bytemark.co.uk/pub/cpt-city/
  • There are a number of command line tools for working with the GMT .cpt files at
http://soliton.vm.bytemark.co.uk/pub/jjg/en/code/cptutils/

Examples

Built in

The numeric values of following color tables can be found in the here






























Addons

These user contributions can be found in the GRASS addons SVN repository







  • The script used to create these thumbnails can be found on the discussion page.

Using GRASS color palettes in QGIS

Most of them can already be found there, you just have to hunt for them. In the raster layer properties window's style tab, select "Singleband pseudocolor" as the type, "Generate new color map", "New color ramp", for ramp type choose "cpt-city", change to the "Sort by Author" tab, and look for "grass". They can also be found in the QGIS section cpt-city's QGIS theme.

If there's a new set of color rules which are not in QGIS, you can prepare a .svg palette file for use with QGIS using the following commands. Consider to then open a ticket in the QGIS issue tracker asking them to add it (and attach the file of course to save someone some work :)

You will need the cptsvg command line tool from cptutils and the GRASS 6 addon module r.out.gmt.

Examples:

 g.region n=100 s=0 w=0 e=100 res=1
 r.mapcalc "dummy = row()"
 
 r.colors dummy color=roygbiv
 r.out.gmt dummy out=roygbiv
 rm roygbiv.grd
 cptsvg --geometry=300x45 -o roygbiv.svg -v roygbiv.cpt
 
 r.colors dummy rules=~/grass/svn/grass-addons/grass6/raster/r.colors.tools/palettes/palette_sst.gcolors
 r.out.gmt dummy out=palette_sst
 rm palette_sst.grd
 cptsvg --geometry=300x45 -o palette_sst.svg -v palette_sst.cpt

You can then copy the resulting .svg file into /usr/share/qgis/resources/cpt-city-qgis-min/grass/ on Linux (or C:\Program Files\QGIS VERSION\apps\qgis\resources\cpt-city-qgis-min\grass\ on MS Windows).

Another solution to export raster color tables is to slightly tweak the output of r.colors.out, in order to provide QGIS with a regular color chart source file. It might be handy when dealing with maps produced by r.composite, i.e. unregistered color charts. The example bellow may be adapted to ones needs (here the alpha channel defaults to 255):

r.colors.out map=my_raster rules=~/in.colors
cat in.colors|sed 's/:/,/'g|sed 's/ /,/'g|awk 'BEGIN {FS=",";OFS=","};{print $1,$2,$3,$4,255,$1}'>out.colors

Loading QGIS color palettes into GRASS

The GRASS GIS addon module r.cpt2grass can be used after the svgx command line program from the cptutils package, using GMT's .cpt color table format as a go-between:

 svgx --output dkbluered.cpt --type cpt  /usr/share/qgis/resources/cpt-city-qgis-min/h5/dkbluered.svg
 r.cpt2grass in=dkbluered.cpt output=dkbluered.gcolors

You can then use the *.gcolors file with the r.colors rules= option (or set the color rules directly from the r.cpt2grass module).