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
| Parameter | Description |
|---|---|
raster_obj | The input raster object. |
geom | The geometry that defines the tile boundary. |
export_options | The export options in JSON format. Default value: '' (empty string). For details, see Export options. |
Return value
Returns a record with the following fields:
| Field | Description |
|---|---|
ext | The image format of the output tile. |
data | The 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.
| Option | Type | Default | Description |
|---|---|---|---|
bands | cstring | '' | The bands to include in the output. Separate multiple bands with commas (,). By default, all bands are returned. |
format | cstring | PNG | The image format of the output tile. Valid values: PNG, JPEG, GTiff. |
pyramid_level | integer | -1 | The pyramid level to use. By default, the optimal band is selected automatically. |
dim | integer | 256 | The pixel size of the output tile. Valid values: 256, 512. |
nodata | boolean | true | Specifies whether to apply the nodata value. If not set, the nodata value of the raster object is used. |
nodatavalue | f8 | 0 | The nodata value to apply. Valid only when nodata is true. |
strength | string | none | The display enhancement method. Valid values: none (no enhancement), stats (stretch based on statistical values), ratio (stretch based on ratios). |
ratio_offset | integer | 2 | The percentage offset for ratio-based stretching. Enhancement is applied from the nth percentile to the (100-n)th percentile. |
alpha | boolean | false | Specifies whether to add an alpha channel for transparency. |
quality | integer | 75 | The 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;