The ST_Reclassify function returns a raster object. The returned object has the same spatial reference and resolution as the original image. The number of bands is specified by the relassexpr parameter.

Syntax

raster ST_Reclassify(raster raster_obj,
                 cstring reclassexpr default NULL
                 cstring storageOption default '')

Parameters

Parameter Description
raster_obj The raster object to be reclassified.
reclassexpr The JSON string is used to indicate a numerical interval for classification.
storageOption The storage option that is represented by a JSON string in the returned result.

The reclassexpr parameter indicates a JSON string array. Each child JSON object indicates a band operation parameter. The following table describes the parameters.

Parameter Description Type Default value Notes
band The band sequence number. integer None The band sequence number starts from 0.
remap The parameter that is used for classification. object - -
nodata Specifies whether to use nodata. boolean false
  • If you set this parameter to true, the pixel value is nodata and the classification result is also nodata.
  • If you set this parameter to false, non-nodata values are calculated as general numeric values.
nodataValue The nodata value. float8 0 The new nodata value.

The remap parameter specifies how to map original pixel values to new pixel values.

  • The key indicates the original pixel value range and consists of one or more numeric values that are separated with commas (,). You can specify an open or closed range at the start and end.
    • A left parenthesis "(" indicates greater than.
    • A right parenthesis ")" indicates less than.
    • A right bracket "]" indicates less than or equal to.
    • A left bracket "[" indicates greater than or equal to.

    The default value is (].

  • The value indicates the result of the mapping from original to new pixel values and consists of one or more numeric values that are separated with commas (,).
  • Three mapping methods are available:
    • Range-to-range mapping: The original and new pixel ranges have the same number of numeric values. Examples: "300,400,500":"80,90,100" and "[300,400,500]":"80,90,100".
    • Range-to-value mapping: The original pixel range has one more numeric value than the new pixel range. Example: "(300,400,500]":"80,90".
    • Value-to-value mapping: The original and new pixel ranges both have only one numeric value. Example: "10":"1".
  • If a pixel value does not belong to a mapping range, the pixel value is considered as a nodata value.
  • Multiple ranges cannot contain the same pixel value.
  • Examples
    • Example 1

      The following example shows how to reclassify band 0:

      if 0<old_value<=100
          new_value = 20
      else if 100<old_value<=200
          new_value = 50
      else
          new_value = 0
      [ 
         { 
            "band":0,
            "remap":{ 
                  "(0,100,200]":"20,50"
            }
         }
      ]
    • Example 2

      Multiple segmented values are supported. Pixel values beyond the range are set to nodata values.

      [ 
         { 
            "band":0,
            "remap":{ 
                  "(0,100,200]":"20,50",
                  "(300,400,500]":"80,90,100"
            }
         }
      ]
    • Example 3

      The following example shows how to reclassify band 0:

      if 0<old_value<=100
          new_value = 20
      else if 100<old_value<=200
          new_value = 50
      else
          new_value = 999

      The following example shows how to reclassify band 1:

      if 400<old_value<=600
          new_value = 20+(old_value-400)/200 * (90-20)
      else if 600<old_value<=800
          new_value = 90+(old_value-600)/200 * (130-90)
      else
          new_value = 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
         }
      ]

The following table describes the parameters of storageOption.

Parameter Description Type Default value Notes
chunking Specifies whether to store data as chunks. boolean Same as the original raster -
chunkdim The dimension information about the chunk. string Same as the original raster This parameter only takes effect when the chunking parameter is set to true.
chunktable The name of the chunk table. string '' If the '' value is passed, a temporary chunk table that has a random name is generated to store data. This temporary table is valid in only the current session. If you need to retain an accessible clipping object, you must specify the name of the chunk table.
compression The type of the compression algorithm. string Same as the original raster Only none, jpeg, zlib, png, lzo, and lz4 are supported.
quality The compression quality. integer Same as the original raster This parameter only takes effect for the jpeg compression algorithm.
interleaving The interleaving method. string Same as the original raster The value must be one of the following types:
  • bip: band interleaved by pixel (BIP)
  • bil: band interleaved by line (BIL)
  • bsq: band sequential (BSQ)
endian The endian. string Same as the original raster The value must be one of the following types:
  • NDR: little endian
  • XDR: big endian
celltype The pixel type. string Same as the original raster -

Examples

-- Create a permanent table.
CREATE TABLE rast_reclassify_result(id integer, rast raster);
-- Create a temporary table.
CREATE TEMP TABLE rast_reclassify_result_temp(id integer, rast raster);

-- Store the result in a 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