Name

ST_AsPNG — 将栅格图块选定的波段作为单个便携式网络图形 (PNG) 图像(字节数组)返回。 如果栅格中有 1、3 或 4 个波段且未指定波段,则使用所有波段。 如果有 2 个以上或多于 4 个波段且未指定波段,则仅使用波段 1。 波段映射到 RGB 或 RGBA 空间。

Synopsis

bytea ST_AsPNG(raster rast, text[] options=NULL);

bytea ST_AsPNG(raster rast, integer nband, integer compression);

bytea ST_AsPNG(raster rast, integer nband, text[] options=NULL);

bytea ST_AsPNG(raster rast, integer[] nbands, integer compression);

bytea ST_AsPNG(raster rast, integer[] nbands, text[] options=NULL);

描述

将栅格的选定波段作为单个便携式网络图形图像 (PNG) 返回。 如果需要导出为不太常见的栅格类型,请使用ST_AsGDALRaster。 如果未指定波段,则导出前 3 个波段。 该功能有许多变体和许多选项。 如果未指定 srid,则使用栅格的 srid。 以下逐项列出:

  • nband 用于单波段导出。

  • nbands 是要导出的波段数组(请注意,PNG 的最大值为 4),波段的顺序为 RGBA。 例如 ARRAY[3,2,1] 表示将波段 3 映射到红色,将波段 2 映射到绿色,将波段 1 映射到蓝色

  • compression编号从 1 到 9。数字越大,压缩越大。

  • options text 为 PNG 定义的 GDAL 选项数组(请查看 ST_GDALDrivers 的 PNG 的 create_options)。 对于 PNG 来说,有效的只是 ZLEVEL(压缩所花费的时间——默认 6),例如 数组['ZLEVEL=9']。 不允许 WORLDFILE,因为该函数必须输出两个输出。 有关更多详细信息,请参阅 GDAL 栅格格式选项

可用性:2.0.0 - 需要 GDAL >= 1.6.0。

示例

SELECT ST_AsPNG(rast) As rastpng
FROM dummy_rast WHERE rid=2;

-- export the first 3 bands and map band 3 to Red, band 1 to Green, band 2 to blue
SELECT ST_AsPNG(rast, ARRAY[3,1,2]) As rastpng
FROM dummy_rast WHERE rid=2;