All Products
Search
Document Center

ApsaraDB RDS:ST_AsJPEG

Last Updated:Mar 28, 2026

Converts a raster into a JPEG image and returns it as a bytea value.

Syntax

bytea ST_AsJPEG(raster raster_obj,
                box extent,
                integer pyramidLevel default 0,
                cstring bands default '',
                cstring option default '');

Parameters

ParameterDescription
raster_objThe raster to convert.
extentThe spatial extent of the data to extract. By default, interpreted as geographic coordinate system (GCS) coordinates.
pyramidLevelThe pyramid level from which to extract data. Valid values start from 0. Default value: 0.
bandsThe bands to include in the output. JPEG requires exactly 3 bands. Accepted formats: a continuous range starting from 0 (e.g., '0-2'), or a comma-separated list of band indexes starting from 0 (e.g., '0,2,4'). If left blank, bands 0, 1, and 2 are used.
optionA JSON string of conversion options. See the Options section for details.

Options

The option parameter accepts a JSON string with the following fields.

FieldTypeDefaultDescription
nodataboolfalseSpecifies whether to process NoData values. true: process NoData values. false: treat NoData values as normal values.
nodataValueinteger0The NoData value of the raster. Required when nodata is true.
rast_coordboolfalseSpecifies whether the extent box uses pixel coordinates. When true, the x-coordinate is the column index and the y-coordinate is the row index, both starting from 0.
strengthstringnoneThe display enhancement mode. none: no enhancement. stats: stretch based on statistical values.
qualityinteger75The compression quality of the output JPEG. Valid values: 1 to 100.

Usage notes

  • The function returns the JPEG image as a bytea value.

  • The valid band counts for output are:

    • 1: single-band raster, converted to a grayscale image.

    • 3: three-band raster using R, G, and B bands.

  • The default cache size for extracted data is 100 MB. To increase the limit, adjust ganos.raster.clip_max_buffer_size.

Examples

Extract data by extent:

SELECT ST_AsJPEG(raster_obj,
                  '(-180,-90), (0,0)'::Box)
FROM raster_table
WHERE id = 1;

Specify a pyramid level:

SELECT ST_AsJPEG(raster_obj,
                  '(-180,-90), (0,0)'::Box,
                 1)
FROM raster_table
WHERE id = 1;

Specify bands using a range:

SELECT ST_AsJPEG(raster_obj,
                  '(-180,-90), (0,0)'::Box,
                 1,
                 '0-2')
FROM raster_table
WHERE id = 1;

Apply statistical stretching enhancement:

SELECT ST_AsJPEG(rast,
                  '(-180,-90), (0,0)'::Box,
                  0,
                  '',
                  '{"nodata":"false", "nodatavalue":"0","rast_coord":"false", "strength":"stats", "quality":"75"}')
FROM raster_table
WHERE id = 1;