The ST_Reclassify function returns a raster object. The resulting object has the same spatial reference and resolution as the original raster. The number of bands is specified by the reclassexpr parameter.
Syntax
raster ST_Reclassify(raster raster_obj,
cstring reclassexpr default NULL
cstring storageOption default '')Parameters
Parameter Name | Description |
raster_obj | The raster object to reclassify. |
reclassexpr | A JSON string that specifies the numerical intervals for classification. |
storageOption | A JSON string that specifies the storage options for the result. |
The reclassexpr parameter is an array of JSON objects. Each object specifies the operation parameters for a band. The parameters are as follows.
Parameter Name | Description | Type | Default value | Notes |
band | The band number. | integer | None | The band number. The value starts from 0. |
remap | The parameters used for classification. | object | - | - |
nodata | Specifies whether to use nodata. | boolean | false |
|
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 represents the original pixel value range. It consists of one or more numerical values separated by commas. You can specify open or closed boundaries for the range.
(Indicates a value greater than)
A right parenthesis `)` means less than.
A right bracket `]` means less than or equal to.
A left bracket `[` means greater than or equal to.
The default is
(].The value represents the new pixel value that results from the mapping. It consists of one or more numerical values separated by commas.
Three mapping methods are available:
Range-to-range: The number of values that define the original pixel range is the same as the number of values that define the new pixel range. For example, "300,400,500":"80,90,100" and "[300,400,500]":"80,90,100".
Range-to-value: The original pixel range is defined by one more value than the new pixel range. For example, "(300,400,500]":"80,90".
Value-to-value: The original and new pixel ranges are each defined by a single value. For example, "10":"1".
Pixel values that do not fall into any specified mapping range are set to the nodata value.
A pixel value cannot be included in multiple ranges.
Examples
Example 1
The following example shows a reclassification operation on band 0:
if 0<old_value<=100 new_value = 20 else if100<old_value<=200 new_value = 50 else new_value = 0[ { "band":0, "remap":{ "(0,100,200]":"20,50" } } ]Example 2
You can specify multiple value segments. Pixel values outside the specified ranges are set to the nodata value.
[ { "band":0, "remap":{ "(0,100,200]":"20,50", "(300,400,500]":"80,90,100" } } ]Example 3
The following example demonstrates a reclassification operation on band 0:
if 0<old_value<=100 new_value = 20 else if100<old_value<=200 new_value = 50 else new_value = 999and a reclassification operation on band 1:
if 400<old_value<=600 new_value = 20+(old_value-400)/200 * (90-20) else if600<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 storageOption parameters are as follows.
Parameter Name | Description | Type | Default value | Notes |
chunking | Specifies whether to use chunk-based storage. | boolean | Same as the original raster | - |
chunkdim | The dimension information of the chunk. | string | Same as the original raster | This parameter takes effect only when chunking is set to true. |
chunktable | The name of the chunk table. | string | '' | If an empty string ('') is passed, a temporary chunk table with a random name is created to store the data. This temporary table is valid only for the current session. To maintain an accessible clipped object, specify a chunk table name. |
compression | The type of compression algorithm. | string | Same as the original raster | The supported algorithms are none, jpeg, zlib, png, lzo, and lz4. |
quality | The compression quality. | integer | Same as the original raster | This parameter applies only to the JPEG compression algorithm. |
interleaving | The interleaving method. | string | Same as the original raster | Must be one of the following:
|
endian | The byte order. | string | Same as the original raster | Must be one of the following:
|
celltype | The pixel type. | string | Same as the original raster | - |
Example
-- A permanent table
CREATE TABLE rast_reclassify_result(id integer, rast raster);
-- A temporary table
CREATE TEMP TABLE rast_reclassify_result_temp(id integer, rast raster);
-- 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