Converts a raster to a bytea PNG image by clipping it to a specified extent.
Syntax
bytea ST_AsPNG(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 extent to clip. Uses the geographic coordinate system by default. |
pyramidLevel | The pyramid level of the image. Valid values start from 0. Default value: 0. |
bands | The bands to include in the output image. Valid values start from 0. Use a range ('0-2') or a comma-separated list ('1,2,3'). Leave blank to use the first three bands. PNG supports 1, 2, 3, or 4 bands — see Usage notes for details. |
option | Options for the conversion, as a JSON string. |
option fields
| Field | Type | Default | Description |
|---|---|---|---|
nodata | bool | false | Specifies whether to treat NoData values differently from normal values. true: processes NoData values as NoData. false: treats 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, x is the column number and y is the row number, both starting from 0. |
strength | string | none | Display enhancement mode. none: no enhancement. stats: stretching based on statistical values. |
quality | integer | 75 | PNG compression quality. Valid values: 1 to 100. |
Usage notes
Returns a bytea PNG image.
By default, up to 100 MB of clipped data is cached, which is also the maximum size of the returned image. To adjust this limit, set the
ganos.raster.clip_max_buffer_sizeparameter.The
bandsparameter determines the PNG image type:Band count Image type 1Grayscale 2Grayscale with Alpha band 3R, G, B 4R, G, B, Alpha band
Examples
Return a PNG image clipped to a geographic extent:
SELECT ST_AsPNG(raster_obj,
'(-180,-90), (0,0)'::Box)
FROM raster_table
WHERE id = 1;Specify the pyramid level:
SELECT ST_AsPNG(raster_obj,
'(-180,-90), (0,0)'::Box,
1)
FROM raster_table
WHERE id = 1;Specify the band range:
SELECT ST_AsPNG(raster_obj,
'(-180,-90), (0,0)'::Box,
1,
'0-2')
FROM raster_table
WHERE id = 1;Apply statistical stretch enhancement:
SELECT ST_AsPNG(rast,
'(-180,-90), (0,0)'::Box,
0,
'',
'{"nodata":"false", "nodatavalue":"0","rast_coord":"false", "strength":"stats", "quality":"75"}')
FROM raster_table
WHERE id = 1;