All Products
Search
Document Center

ApsaraDB RDS:ST_SubRaster

Last Updated:Mar 28, 2026

Extracts a specified pyramid level or band subset from a raster object and returns the result as a new raster object.

Syntax

raster ST_SubRaster(raster raster_obj,
                    integer pyramidLevel default 0,
                    cstring bands default '',
                    cstring storageOption default '',
                    cstring options default '{}')

Parameters

ParameterTypeDefaultDescription
raster_objrasterThe source raster object.
pyramidLevelinteger0The pyramid level to extract.
bandscstring''The bands to extract. Accepts an integer range ('0-2') or a comma-separated list ('1,2,3'). Band indexes start at 0. The default value ('') extracts all bands.
storageOptioncstring''A JSON string that controls how the new raster object is stored. See storageOption parameters.
optionscstring'{}'A JSON string that controls how the new raster object is generated. See options parameters.

storageOption parameters

All storageOption sub-parameters are optional. Parameters not specified inherit the value from the source raster object.

Commonly used parameters

ParameterTypeDefaultDescription
chunktablestring''The name of the chunk table for the new raster object. If set to '' or NULL, a temporary chunk table with a random name is created and is valid only for the current session. Specify a name to create a permanent chunk table.
compressionstringSame as sourceThe compression format. Valid values: NONE, JPEG, ZLIB, PNG, LZO, LZ4.
celltypestringSame as sourceThe pixel type. Valid values: 1bb, 2bui, 4bui, 8bsi, 8bui, 16bsi, 16bui, 32bsi, 32bui, 64bsi, 64bui, 32bf, 64bf.
chunkingbooleanSame as sourceSpecifies whether to store the new raster object in chunks.

Advanced parameters

ParameterTypeDefaultDescription
chunkdimstringSame as sourceThe chunk dimensions. Valid only when chunking is true.
qualityintegerSame as sourceThe image quality after compression (1–99). Valid only when compression is JPEG.
interleavingstringSame as sourceThe interleaving type. Valid values: bip (band interleaved by pixel, BIP), bil (band interleaved by line, BIL), bsq (band sequential, BSQ).
endianstringSame as sourceThe byte order. Valid values: NDR (little-endian), XDR (big-endian).

options parameters

ParameterTypeDefaultDescription
parallelintegerganos.parallel.degreeThe degree of parallelism. Valid values: 1–64.
stretchstringnoneThe pixel value stretch method. Valid values: none (replaces out-of-range values with the nearest extremum), stats (stretches based on raster statistics — requires precomputed statistics; see note below), data_type (stretches based on the pixel type's value range).
When stretch is set to stats, the source raster object must have precomputed statistics. Call ST_SummaryStats on the source raster object before calling ST_SubRaster.

Examples

Extract bands from a raster object

Extract bands 0 through 2 from pyramid level 1 and store the result in a permanent chunk table.

SELECT ST_SubRaster(rast, 1, '0-2', '{"chunktable":"chunk_table", "chunking":true}')
FROM raster_sub
WHERE id = 1;

Convert pixel type and stretch pixel values in parallel

Convert to 8-bit unsigned integer (8BUI) using data_type stretch with a parallelism of 4.

SELECT ST_SubRaster(rast, 1, '0-2', '{"chunktable":"chunk_table", "chunking":true, "celltype": "8BUI"}', '{"stretch": "data_type", "parallel": 4}')
FROM raster_sub
WHERE id = 1;