Returns the color table of a raster band as a JSON string.
Syntax
text ST_ColorTable(raster raster_obj, integer band);Parameters
| Parameter | Description |
|---|---|
raster_obj | The raster object. |
band | The sequence number of the band. Band numbering starts from 0. |
Return value
A JSON string with the following structure:
| Field | Description |
|---|---|
compsCount | The number of color components: 3 or 4. |
entries | An array of color table entries. Each entry maps a pixel value to its color components. |
value | The pixel value. |
c1 | Color component 1. |
c2 | Color component 2. |
c3 | Color component 3. |
c4 | Color component 4. Present only when compsCount is 4. |
Four color components:
{
"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}
]
}Three color components:
{
"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}
]
}If the band does not have a color table, the function returns null.Examples
Query the color table of band 0 from a raster object:
SELECT ST_ColorTable(raster_obj, 0) FROM raster_table WHERE id = 1;Expected 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}
]
}