ST_AsPNG

更新时间:
复制 MD 格式

Encodes a raster object as a binary stream in the PNG format.

Syntax

bytea ST_AsPNG(raster raster_obj,box extent,
        integer pyramidLevel default 0,
         cstring bands default '',
               cstring option default '');

Parameters

Parameter Name

Description

raster_obj

The raster object to process.

extent

The extent of the image. The geographic coordinate system is used by default.

pyramidLevel

The pyramid level of the image. The value starts from 0. The default value is 0.

bands

The list of bands to retrieve. The value starts from 0. Use a format such as '0-2' or '1,2,3'. The default value is empty. A PNG image can have 1, 2, 3, or 4 bands. By default, the first three bands are used.

option

The conversion options in a JSON string.

The following describes the option parameter.

Parameter

Description

Type

Default value

Notes

nodata

Specifies whether to use a NoData value.

bool

false

  • true: Processes Nodata values.

  • false: The NoData value is processed as a normal value.

nodataValue

The NoData value.

integer

0

If nodata is set to true, you must set a value for this parameter.

rast_coord

Specifies whether the input box uses pixel coordinates.

bool

false

If pixel coordinates are used, x indicates the column number of the pixel and y indicates the row number. Both the column and row numbers start from 0.

strength

Specifies whether to enhance the image.

string

none

The enhancement method. Valid values:

  • none: No enhancement is performed.

  • stats: The image is stretched based on statistical values.

quality

The compression quality.

integer

75

The compression quality. Valid values: 1 to 100.

Description

  • The function returns the image data in bytea format.

  • The default clipping cache is 100 MB. This means the resulting data cannot exceed 100 MB. To change the cache size, use the ganos.raster.clip_max_buffer_size parameter.

  • The number of bands is as follows:

    • 1: A grayscale image.

    • 2: A grayscale band and an alpha band.

    • 3: The R, G, and B bands.

    • 4: The R, G, B, and alpha bands.

Examples

-- Use a clipping range.
SELECT ST_AsPNG(raster_obj, 
                  '(-180,-90), (0,0)'::Box) 
FROM raster_table    
WHERE id =1;

-- Specify a pyramid level.
SELECT ST_AsPNG(raster_obj, 
                  '(-180,-90), (0,0)'::Box,
                 1) 
FROM raster_table    
WHERE id =1;

-- Specify bands and a clipping range.
SELECT ST_AsPNG(raster_obj, 
                  '(-180,-90), (0,0)'::Box,
                 1,
                 '0-2') 
FROM raster_table    
WHERE id =1;

-- Stretch the image using statistical values.
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;