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
| Parameter | Description |
|---|---|
raster_obj | The raster to convert. |
extent | The spatial extent of the data to extract. By default, interpreted as geographic coordinate system (GCS) coordinates. |
pyramidLevel | The pyramid level from which to extract data. Valid values start from 0. Default value: 0. |
bands | The 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. |
option | A JSON string of conversion options. See the Options section for details. |
Options
The option parameter accepts a JSON string with the following fields.
| Field | Type | Default | Description |
|---|---|---|---|
nodata | bool | false | Specifies whether to process NoData values. true: process NoData values. false: treat NoData values as normal values. |
nodataValue | integer | 0 | The NoData value of the raster. Required when nodata is true. |
rast_coord | bool | false | Specifies 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. |
strength | string | none | The display enhancement mode. none: no enhancement. stats: stretch based on statistical values. |
quality | integer | 75 | The compression quality of the output JPEG. Valid values: 1 to 100. |
Usage notes
The function returns the JPEG image as a
byteavalue.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;