All Products
Search
Document Center

PolarDB:ST_AsTile

Last Updated:Mar 28, 2026

Crops a 256 or 512 pixel tile from a raster object within the specified geometry bounds and returns it as a binary stream. Outputs PNG format with all bands included by default.

Syntax

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

Return values

Returns a record with two fields:

FieldTypeDescription
extThe image format of the output tile
databyteaThe binary tile data (256 or 512 pixels)

Parameters

ParameterTypeDescription
raster_objrasterThe input grid object
geomgeometryThe geometry object that defines the tile bounds
export_optionscstringA JSON string of export options. Defaults to '' (empty string).

Export options

Pass export_options as a JSON string. All fields are optional.

OptionTypeDefaultDescription
bandscstring''The bands to include in the output, separated by commas. By default, all bands are included.
formatcstringPNGThe output image format. Valid values: PNG, JPEG, GTiff.
pyramid_levelinteger-1The pyramid level to use. Defaults to -1, which selects the optimal level automatically.
diminteger256The pixel size of the output tile. Valid values: 256, 512.
nodatabooleantrueSpecifies whether to apply the nodata value. If you do not specify this option, the nodata value of the object is used.
nodatavaluef80The nodata value to apply. Takes effect 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 enhancement. Stretches the output from the nth to the (100-n)th percentile. Takes effect only when strength is ratio.
alphabooleanfalseSpecifies whether to add an alpha channel for transparency.
qualityinteger75The compression quality. Valid values: 0-100. The value 0 indicates the poorest compression quality, and the value 100 indicates the optimal compression quality.

Examples

Export bands 0, 1, and 2 as PNG

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 GTiff 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;

Export a PNG tile with statistical enhancement and transparency

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