用指定的Geometry对象去裁剪Raster对象,并将裁剪结果作为一个新的Raster对象返回。

语法

raster ST_ClipToRast(raster raster_obj,
                     geometry geom,
                     integer pyramidLevel default 0,
                     cstring bands default '',
                     float8[] nodata default NULL,
                     cstring clipOption default '',
                     cstring storageOption default '')

参数

参数名称描述
raster_obj需要裁剪的Raster对象。
pyramidLevel金字塔层级。
geom用于裁剪的Geometry对象。
bands需要裁剪的波段,用'0-2'或者'1,2,3'这种形式表示,以0开始。默认为'',表示裁剪所有的波段。
nodata用float8[]表示的nodata数值。如果数值个数少于波段数量,则使用波段设置的nodata值填充。如果波段未设置nodata,则用0填充。
clipOptionJSON字符串表示的裁剪选项。
storageOptionJSON字符串表示的返回结果的存储选项。

clipOption参数如下。

参数名称类型默认值描述
window_clipboolfalse是否使用Geometry的外包框进行裁剪。取值:
  • true:使用Geometry的MBR裁剪。
  • false:使用Geometry对象裁剪。
rast_coordboolfalse传入的Geometry是否使用的是象元坐标。如果是象元坐标,横坐标x表示象元的列号,纵坐标y表示象元的行号。

storageOption参数如下。

参数名称类型默认值描述
chunkingboolean和原始Raster一致是否使用分块存储。
chunkdimstring和原始Raster一致分块的维度信息。在chunking=true时才有效。
chunktablestring''分块表名称。如果传入''值,则会产生一个随机表名临时块表用于存放数据。 该临时表只在当前会话中有效。如果需要保持一个可访问的裁剪对象,则需要指定块表名称。
compressionstringlz4压缩算法类型。取值:
  • none
  • jpeg
  • zlib
  • png
  • lzo
  • lz4
qualityinteger75压缩质量,只针对jpeg压缩算法。
interleavingstring和原始Raster一致交错方式。取值:
  • bip:波段按像元交叉
  • bil:波段按行交叉
  • bsq:波段顺序
endianstring和原始Raster一致字节序。取值:
  • NDR:小字节序(Little endian)
  • XDR:大字节序(Big endian)

描述

  • 如果chunkTable传入为NULL或者'', 则会产生一个随机表名的临时块表用于存放数据,该临时表只在当前会话中有效。如果需要保持一个可访问的裁剪对象,则需要指定块表名称。
  • 默认的裁剪缓存为100 MB,代表最多只能裁剪出100 MB大小的结果数据,如果需要调整返回结果大小,可使用参数ganos.raster.clip_max_buffer_size设置缓存的大小。

示例

-- 永久表
CREATE TEMP TABLE rast_clip_result(id integer, rast raster);

-- 临时表
CREATE TEMP TABLE rast_clip_result_temp(id integer, rast raster);

-- 默认裁剪并存放到临时表中
INSERT INTO rast_clip_result_temp(id, rast) 
select 1, ST_ClipToRast(rast, ST_geomfromtext('Polygon((0 0, 45 45, 90 45, 45 0, 0 0))', 4326), 0) 
from clip_table 
where id =1;

-- 使用白色作为背景色填充,并保存到永久表中
INSERT INTO rast_clip_result(id, rast) 
select 2, ST_ClipToRast(rast, ST_geomfromtext('Polygon((0 0, 45 45, 90 45, 45 0, 0 0))', 4326), 0, '', ARRAY[254,254,254], '', '{"chunktable":"clip_rbt"}') 
from clip_table 
where id =1;

-- 使用Geometry的窗口裁剪
INSERT INTO rast_clip_result_temp(id, rast) 
SELECT 3, ST_ClipToRast(rast, ST_geomfromtext('Polygon((0 0, 45 45, 90 45, 45 0, 0 0))', 4326), 0, '', NULL, '{"window_clip":true}', '') 
from clip_table 
where id =1;