Returns the color table of a specified band in a raster object, encoded as JSON. Returns null if the band has no color table.
Syntax
text ST_ColorTable(raster raster_obj, integer band);Parameters
| Parameter | Type | Description |
|---|---|---|
raster_obj | raster | The raster object. |
band | integer | The band index. Starts from 0. |
Description
The returned JSON object has the following top-level fields:
| Field | Type | Description |
|---|---|---|
compsCount | integer | The number of color components. 3 = three components; 4 = four components. |
entries | array | The color table entries. Each entry maps a pixel value to its color components. |
Each entry in entries has the following fields:
| Field | Description |
|---|---|
value | The pixel value. |
c1 | Component 1. |
c2 | Component 2. |
c3 | Component 3. |
c4 | Component 4. Present only when compsCount is 4. |
JSON format
3-component:
{
"compsCount": 3,
"entries": [
{"value": 0, "c1": 0, "c2": 0, "c3": 0},
{"value": 1, "c1": 0, "c2": 0, "c3": 85},
{"value": 2, "c1": 0, "c2": 0, "c3": 170}
]
}4-component:
{
"compsCount": 4,
"entries": [
{"value": 0, "c1": 0, "c2": 0, "c3": 0, "c4": 255},
{"value": 1, "c1": 0, "c2": 0, "c3": 85, "c4": 255},
{"value": 2, "c1": 0, "c2": 0, "c3": 170, "c4": 255}
]
}Examples
Retrieve the color table for band 0 of a raster object:
SELECT ST_ColorTable(raster_obj, 0)
FROM raster_table
WHERE id = 1;Output:
{
"compsCount": 3,
"entries": [
{"value": 0, "c1": 0, "c2": 0, "c3": 0},
{"value": 1, "c1": 0, "c2": 0, "c3": 85},
{"value": 2, "c1": 0, "c2": 0, "c3": 170}
]
}