All Products
Search
Document Center

PolarDB:ST_Reclassify

Last Updated:Mar 28, 2026

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

ParameterDescription
raster_objThe raster object to reclassify.
reclassexprA JSON string array that defines the classification rules for each band.
storageOptionA 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.

ParameterTypeDefaultDescription
bandintegerThe band index to reclassify. Band indexes start at 0.
remapobjectThe pixel value mapping rules. See remap.
nodatabooleanfalseSpecifies 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.
nodataValuefloat80The 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:

SymbolMeaning
(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:

MethodDescriptionExample
Range-to-rangeInput 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-valueInput has one more value than output. Each interval between consecutive input values maps to one output value."(300,400,500]":"80,90"
Value-to-valueBoth 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

ParameterTypeDefaultDescription
chunkingbooleanSame as inputSpecifies whether to store the raster as chunks.
chunkdimstringSame as inputThe chunk dimensions. Takes effect only when chunking is true.
chunktablestring''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.
compressionstringSame as inputThe compression algorithm. Valid values: none, jpeg, zlib, png, lzo, lz4.
qualityintegerSame as inputThe compression quality. Takes effect only for jpeg compression.
interleavingstringSame as inputThe interleaving method. Valid values: bip (band interleaved by pixel, BIP), bil (band interleaved by line, BIL), bsq (band sequential, BSQ).
endianstringSame as inputThe byte order. Valid values: NDR (little endian), XDR (big endian).
celltypestringSame as inputThe 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;