All Products
Search
Document Center

PolarDB:ST_AsTile

Last Updated:Mar 28, 2026

Crops a tile from a raster object within a specified geometry boundary and returns it as a binary stream in the requested image format.

Syntax

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

Return values

Returns a record with the following fields:

FieldTypeDescription
extThe image format of the output tile. For example, PNG, JPEG, or GTiff.
databyteaThe binary image data of the tile (256 or 512 pixel-sized).

Parameters

ParameterDescription
raster_objThe input raster object.
geomThe geometry that defines the tile boundary.
export_optionsA JSON string that controls the output format and rendering. Defaults to '' (empty).

export_options

Pass export_options as a JSON string. The following options are supported.

OptionTypeDefaultDescription
formatcstringPNGThe output image format. Valid values: PNG, JPEG, GTiff.
bandscstring''The bands to include in the output, specified as a comma-separated list (for example, "0,1,2"). If not set, all bands are returned.
qualityinteger75The compression quality. Valid values: 0 to 100, where 0 is the lowest quality and 100 is the highest.
diminteger256The tile size in pixels. Valid values: 256, 512.
pyramid_levelinteger-1The pyramid level to read from. Defaults to -1, which selects the optimal level automatically.
nodatabooleantrueSpecifies whether to apply nodata masking. If not set, the raster object's own nodata value is used.
nodatavaluef80The nodata value to apply. Takes effect only when nodata is true.
strengthstringnoneThe image enhancement mode. Valid values: none (no enhancement), stats (contrast stretch based on statistical values), ratio (contrast stretch based on ratios).
ratio_offsetinteger2The clip percentage used when strength is ratio. A value of 2 clips the darkest 2% and brightest 2% of pixel values before stretching, which prevents extreme outliers from compressing the visible range.
alphabooleanfalseSpecifies whether to add an alpha channel for transparency.

Examples

Export a PNG tile with RGB bands

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 a GeoTIFF tile at a specific pyramid level

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 JPEG tile with compression quality and enhancement

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

Export a PNG tile with 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","alpha":true}'
)
FROM raster_table;