Skip to content

r.colors.out

Exports the color table associated with a raster map.

r.colors.out [-p] map=name [rules=name] format=name color_format=name [--overwrite] [--verbose] [--quiet] [--qq] [--ui]

Example:

r.colors.out map=name format=plain color_format=hex

grass.script.parse_command("r.colors.out", map, rules=None, format="plain", color_format="hex", flags=None, overwrite=False, verbose=False, quiet=False, superquiet=False)

Example:

gs.parse_command("r.colors.out", map="name", format="json", color_format="hex")

Parameters

map=name [required]
    Name of raster map
rules=name
    Path to output rules file
    If not given write to standard output
format=name [required]
    Output format
    Allowed values: plain, json
    Default: plain
    plain: Plain text output
    json: JSON (JavaScript Object Notation)
color_format=name [required]
    Color format
    Color format for output values.
    Allowed values: rgb, hex, hsv, triplet
    Default: hex
    rgb: output color in RGB format
    hex: output color in HEX format
    hsv: output color in HSV format (experimental)
    triplet: output color in colon-separated RGB format
-p
    Output values as percentages
--overwrite
    Allow output files to overwrite existing files
--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 raster map
    Used as: input, raster, name
rules : str, optional
    Path to output rules file
    If not given write to standard output
    Used as: output, file, name
format : str, required
    Output format
    Used as: name
    Allowed values: plain, json
    plain: Plain text output
    json: JSON (JavaScript Object Notation)
    Default: plain
color_format : str, required
    Color format
    Color format for output values.
    Used as: name
    Allowed values: rgb, hex, hsv, triplet
    rgb: output color in RGB format
    hex: output color in HEX format
    hsv: output color in HSV format (experimental)
    triplet: output color in colon-separated RGB format
    Default: hex
flags : str, optional
    Allowed values: p
    p
        Output values as percentages
overwrite: bool, optional
    Allow output files to overwrite existing files
    Default: False
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

r.colors.out allows the user to export the color table for a raster map to a file which is suitable as input to r.colors.

Alternatively, the color rules can be exported as a JSON format with format=json, to use them in other software. The color format in JSON can be modified using the color_format parameter, which includes the following options:

  • hex: #00BFBF
  • rgb: rgb(0, 191, 191)
  • hsv: hsv(180, 100, 74)
  • triplet: 0:191:191

EXAMPLES

r.colors.out map=elevation

Output:

55.5788 0:191:191
75.729 0:255:0
95.8792 255:255:0
116.029 255:127:0
136.18 191:127:63
156.33 20:20:20
nv 255:255:255
default 255:255:255

=== "Python (grass.script)"

```python
import grass.script as gs

colors = gs.parse_command("r.colors.out", map="elevation", format="json")
```

The JSON output looks like:

```json
[
    {
        "value": 55.578792572021484,
        "color": "#00BFBF"
    },
    {
        "value": 75.729006957999999,
        "color": "#00FF00"
    },
    {
        "value": 95.879221344000001,
        "color": "#FFFF00"
    },
    {
        "value": 116.02943573,
        "color": "#FF7F00"
    },
    {
        "value": 136.179650116,
        "color": "#BF7F3F"
    },
    {
        "value": 156.32986450195312,
        "color": "#141414"
    },
    {
        "value": "nv",
        "color": "#FFFFFF"
    },
    {
        "value": "default",
        "color": "#FFFFFF"
    }
]
```

SEE ALSO

r.colors

AUTHOR

Glynn Clements

SOURCE CODE

Available at: r.colors.out source code (history)
Latest change: Wednesday Jun 25 11:38:52 2025 in commit b90b316