All Products
Search
Document Center

ApsaraDB RDS:ST_AsTile

Last Updated:Mar 28, 2026

Crops a tile from a raster object and returns it as a binary stream in the specified image format. The output tile is either 256 or 512 pixels.

Syntax

record ST_AsTile(raster raster_obj, geometry geom, cstring export_options default '');

Parameters

ParameterDescription
raster_objThe input raster object.
geomThe geometry that defines the tile boundary.
export_optionsThe export options in JSON format. Default value: '' (empty string). For details, see Export options.

Return value

Returns a record with the following fields:

FieldDescription
extThe image format of the output tile.
dataThe binary data of the output tile, either 256 or 512 pixels.

Export options

Pass export options as a JSON string to the export_options parameter.

OptionTypeDefaultDescription
bandscstring''The bands to include in the output. Separate multiple bands with commas (,). By default, all bands are returned.
formatcstringPNGThe image format of the output tile. Valid values: PNG, JPEG, GTiff.
pyramid_levelinteger-1The pyramid level to use. By default, the optimal band is selected automatically.
diminteger256The pixel size of the output tile. Valid values: 256, 512.
nodatabooleantrueSpecifies whether to apply the nodata value. If not set, the nodata value of the raster object is used.
nodatavaluef80The nodata value to apply. Valid only when nodata is true.
strengthstringnoneThe display enhancement method. Valid values: none (no enhancement), stats (stretch based on statistical values), ratio (stretch based on ratios).
ratio_offsetinteger2The percentage offset for ratio-based stretching. Enhancement is applied from the nth percentile to the (100-n)th percentile.
alphabooleanfalseSpecifies whether to add an alpha channel for transparency.
qualityinteger75The compression quality. Valid values: 0 to 100. 0 is the lowest quality, 100 is the highest.

Examples

Export bands 0, 1, and 2 as a PNG tile:

SELECT ST_AsTile(
  rast,
  ST_GeomFromText('POLYGON((-80 30,-100 30, -100 100, -80 100, -80 30))', 4326),
  '{"format":"PNG","bands":"0,1,2"}'
) FROM raster_table;

Export bands 0, 1, and 2 as a GTiff tile at pyramid level 7:

SELECT ST_AsTile(
  rast,
  ST_GeomFromText('POLYGON((-80 30,-100 30, -100 100, -80 100, -80 30))', 4326),
  '{"format":"GTiff","bands":"0,1,2","pyramid_level":7}'
) FROM raster_table;