Reclassifies pixel values in a raster object by mapping original values to new values based on a classification expression.
The returned raster has the same spatial reference and resolution as the input. The number of output bands is determined by the reclassexpr parameter.
Syntax
raster ST_Reclassify(raster raster_obj,
cstring reclassexpr DEFAULT NULL,
cstring storageOption DEFAULT '')Parameters
| Parameter | Description |
|---|---|
raster_obj | The raster object to reclassify. |
reclassexpr | A JSON string array that defines the classification rules for each band. |
storageOption | A JSON string that configures the storage format of the returned raster. |
reclassexpr
Each element in the reclassexpr array is a JSON object that specifies reclassification rules for one band.
| Parameter | Type | Default | Description |
|---|---|---|---|
band | integer | — | The band index to reclassify. Band indexes start at 0. |
remap | object | — | The pixel value mapping rules. See remap. |
nodata | boolean | false | Specifies whether to treat nodata pixels as nodata in the output. If true, pixels with the nodata value remain nodata. If false, non-nodata values are calculated as regular numeric values. |
nodataValue | float8 | 0 | The nodata value to assign in the output. |
remap
The remap object maps original pixel value ranges to new pixel values. Each key-value pair defines one mapping rule.
Key format — The key specifies the input pixel value range using interval notation:
| Symbol | Meaning |
|---|---|
( | Greater than (open left boundary) |
) | Less than (open right boundary) |
[ | Greater than or equal to (closed left boundary) |
] | Less than or equal to (closed right boundary) |
The default boundary type is (] (open left, closed right).
Use commas to separate boundary values within the key. For example, (0,100,200] defines two intervals: (0, 100] and (100, 200].
Value format — The value specifies the output pixel values, separated by commas.
Three mapping methods are supported:
| Method | Description | Example |
|---|---|---|
| Range-to-range | Input and output have the same number of values. Each input value maps directly to the corresponding output value. | "300,400,500":"80,90,100" |
| Range-to-value | Input has one more value than output. Each interval between consecutive input values maps to one output value. | "(300,400,500]":"80,90" |
| Value-to-value | Both input and output have exactly one value. A single pixel value maps to a single new value. | "10":"1" |
Constraints:
Pixels outside all defined ranges are treated as nodata.
Ranges cannot overlap (no pixel value can belong to more than one range).
remap examples
Example 1 — Single band, range-to-value mapping
Reclassify band 0:
(0, 100] → 20
(100, 200] → 50
All other values → nodata
[
{
"band": 0,
"remap": {
"(0,100,200]": "20,50"
}
}
]Example 2 — Multiple ranges
Pixels in (200, 300] and other gaps outside defined ranges are set to nodata.
[
{
"band": 0,
"remap": {
"(0,100,200]": "20,50",
"(300,400,500]": "80,90,100"
}
}
]Example 3 — Multi-band with nodata settings
Band 0:
(0, 100] → 20
(100, 200] → 50
All other values → 999 (set as nodata)
Band 1:
(400, 600] → linear interpolation from 20 to 90
(600, 800] → linear interpolation from 90 to 130
All other values → 0
[
{
"band": 0,
"remap": { "(0,100,200]": "20,50" },
"nodata": true,
"nodataValue": 999
},
{
"band": 1,
"remap": { "(400,600,800]": "20,90,130" },
"nodata": false,
"nodataValue": 0
}
]storageOption
| Parameter | Type | Default | Description |
|---|---|---|---|
chunking | boolean | Same as input | Specifies whether to store the raster as chunks. |
chunkdim | string | Same as input | The chunk dimensions. Takes effect only when chunking is true. |
chunktable | string | '' | The name of the chunk table. If left blank (''), a temporary chunk table with a random name is created and is valid only for the current session. Specify a name to retain an accessible raster object after the session ends. |
compression | string | Same as input | The compression algorithm. Valid values: none, jpeg, zlib, png, lzo, lz4. |
quality | integer | Same as input | The compression quality. Takes effect only for jpeg compression. |
interleaving | string | Same as input | The interleaving method. Valid values: bip (band interleaved by pixel, BIP), bil (band interleaved by line, BIL), bsq (band sequential, BSQ). |
endian | string | Same as input | The byte order. Valid values: NDR (little endian), XDR (big endian). |
celltype | string | Same as input | The pixel type of the output raster. |
Examples
-- Create a permanent table to store results.
CREATE TABLE rast_reclassify_result(id integer, rast raster);
-- Create a temporary table to store results.
CREATE TEMP TABLE rast_reclassify_result_temp(id integer, rast raster);
-- Reclassify band 0 and store the result in the temporary table.
INSERT INTO rast_reclassify_result_temp(id, rast)
SELECT 1, ST_Reclassify(rast, '[{"band":0,"remap":{"(0,100,200]":"20,50"}}]')
FROM reclass_table;