# `gdal raster color-map`

Added in version 3.11.

Generate a RGB or RGBA dataset from a single band, using a color map.

## Synopsis

    Usage: gdal raster color-map [OPTIONS] <INPUT> <OUTPUT>

    Generate a RGB or RGBA dataset from a single band, using a color map

    Positional arguments:
      -i, --input <INPUT>                                  Input raster dataset [required]
      -o, --output <OUTPUT>                                Output raster dataset [required]

    Common Options:
      -h, --help                                           Display help message and exit
      --json-usage                                         Display usage as JSON document and exit
      --config <KEY>=<VALUE>                               Configuration option [may be repeated]
      --progress                                           Display progress bar

    Options:
      -f, --of, --format, --output-format <OUTPUT-FORMAT>  Output format ("GDALG" allowed)
      --co, --creation-option <KEY>=<VALUE>                Creation option [may be repeated]
      --overwrite                                          Whether overwriting existing output is allowed
      -b, --band <BAND>                                    Input band (1-based index) (default: 1)
      --color-map <COLOR-MAP>                              Color map filename
      --add-alpha                                          Adds an alpha mask band to the destination.
      --color-selection <COLOR-SELECTION>                  How to compute output colors from input values. COLOR-SELECTION=interpolate|exact|nearest (default: interpolate)

    Advanced Options:
      --if, --input-format <INPUT-FORMAT>                  Input formats [may be repeated]
      --oo, --open-option <KEY>=<VALUE>                    Open options [may be repeated]

## Description

gdal raster color-map generates a RGB or RGBA dataset from a single band, using a color map, either attached directly to a raster band, or from an external text file. It is typically used to create hypsometric maps from a DEM.

This subcommand is also available as a potential step of gdal raster pipeline

### Standard options

-f, --of, --format, --output-format <OUTPUT-FORMAT>

  Which output raster format to use. Allowed values may be given by `gdal --formats | grep raster | grep rw | sort`

--co <NAME>=<VALUE>

  Many formats have one or more optional creation options that can be used to control particulars about the file created. For instance, the GeoTIFF driver supports creation options to control compression, and whether the file should be tiled.

  May be repeated.

  The creation options available vary by format driver, and some simple formats have no creation options at all. A list of options supported for a format can be listed with the --formats command line option but the documentation for the format is the definitive source of information on driver creation options. See Raster drivers format specific documentation for legal creation options for each format.

--overwrite

  Allow program to overwrite existing target file or dataset. Otherwise, by default, gdal errors out if the target file or dataset already exists.

-b, --band <BAND>

  Index (starting at 1) of the band to process.

--color-map <COLOR-MAP>

  Color map filename containing the association between various raster values and the corresponding wished color.

  This option must be specified if the input raster band has no attached color table.

  The text-based color configuration file generally contains 4 columns per line: the raster value and the corresponding Red, Green, Blue component (between 0 and 255). The raster value can be any floating point value, or the `nv` keyword for the nodata value. The raster can also be expressed as a percentage: 0% being the minimum value found in the raster, 100% the maximum value.

  An extra column can be optionally added for the alpha component. If it is not specified, full opacity (255) is assumed.

  Various field separators are accepted: comma, tabulation, spaces, ':'.

  Common colors used by GRASS can also be specified by using their name, instead of the RGB triplet. The supported list is: white, black, red, green, blue, yellow, magenta, cyan, aqua, grey/gray, orange, brown, purple/violet and indigo.

  > GMT `.cpt` palette files are also supported (COLOR_MODEL = RGB only).

  Note: the syntax of the color configuration file is derived from the one supported by GRASS r.colors utility. ESRI HDR color table files (.clr) also match that syntax. The alpha component and the support of tab and comma as separators are GDAL specific extensions.

  For example:

      3500   white
      2500   235:220:175
      50%   190 185 135
      700    240 250 150
      0      50  180  50
      nv     0   0   0   0

  To implement a "round to the floor value" mode, the raster value can be duplicate with a new value being slightly above the threshold. For example to have red in [0,10], green in ]10,20] and blue in ]20,30]:

      0       red
      10      red
      10.001  green
      20      green
      20.001  blue
      30      blue

--addalpha

  Adds an alpha mask band to the output.

--color-selection interpolate|exact|nearest

  How to compute output colors from input values:

  - `interpolate` (default): apply linear interpolation when a raster value falls between two entries of the color map.

  - `exact`: only input raster values matching exacting an entry of the color map will be colorized. If none matching color entry is found, the "0,0,0,0" RGBA quadruplet will be used.

  - `nearest`: input raster values will be assigned the entry of the color map that is the closest.

  Note

  This option is only taken into account when `--color-map` is specified.

## GDALG output (on-the-fly / streamed dataset)

This program supports serializing the command line as a JSON file using the `GDALG` output format. The resulting file can then be opened as a raster dataset using the GDALG: GDAL Streamed Algorithm driver, and apply the specified pipeline in a on-the-fly / streamed way.

## Examples

### Example 1: Generates a RGB dataset from a DTED0 file using an external color map

    $ gdal raster color-map --color-map=color-map.txt n43.dt0 out.tif --overwrite