ST_Clip — 返回由输入几何图形裁剪的栅格。 如果未指定波段号,则处理所有波段。 如果裁剪
未指定或为 TRUE,则输出栅格将被裁剪。
raster ST_Clip(
raster rast, integer[] nband, geometry geom, double precision[] nodataval=NULL, boolean crop=TRUE)
;
raster ST_Clip(
raster rast, integer nband, geometry geom, double precision nodataval, boolean crop=TRUE)
;
raster ST_Clip(
raster rast, integer nband, geometry geom, boolean crop)
;
raster ST_Clip(
raster rast, geometry geom, double precision[] nodataval=NULL, boolean crop=TRUE)
;
raster ST_Clip(
raster rast, geometry geom, double precision nodataval, boolean crop=TRUE)
;
raster ST_Clip(
raster rast, geometry geom, boolean crop)
;
返回由输入几何体 geom
裁剪的栅格。 如果未指定波段索引,则处理所有波段。
ST_Clip 生成的栅格必须为剪切区域分配一个节点数据值,每个波段一个。 如果未提供任何内容,并且输入栅格未定义 nodata 值,则生成的栅格的 nodata 值将设置为 ST_MinPossibleValue(ST_BandPixelType(rast, band))。 当数组中的nodata值的数量小于波段的数量时,数组中的最后一个值用于剩余的波段。 如果节点数据值的数量大于波段数量,则忽略多余的节点数据值。 所有接受节点数据值数组的变体也接受将分配给每个波段的单个值。
如果未指定 crop
参数,默认为 true,这意味着输出的栅格图像将被裁剪为 geom
和 rast
边界的交集部分。如果将 crop
设置为 false,则新的栅格图像将具有与 rast
相同的范围。
可用性: 2.0.0
增强:2.1.0 用 C 重写
此处的示例使用 MassGIS 网站 MassGIS Aerial Orthos 上提供的马萨诸塞州航空数据。 坐标采用马萨诸塞州平面米。
-- Clip the first band of an aerial tile by a 20 meter buffer. SELECT ST_Clip(rast, 1, ST_Buffer(ST_Centroid(ST_Envelope(rast)),20) ) from aerials.boston WHERE rid = 4;
-- Demonstrate effect of crop on final dimensions of raster -- Note how final extent is clipped to that of the geometry -- if crop = true SELECT ST_XMax(ST_Envelope(ST_Clip(rast, 1, clipper, true))) As xmax_w_trim, ST_XMax(clipper) As xmax_clipper, ST_XMax(ST_Envelope(ST_Clip(rast, 1, clipper, false))) As xmax_wo_trim, ST_XMax(ST_Envelope(rast)) As xmax_rast_orig FROM (SELECT rast, ST_Buffer(ST_Centroid(ST_Envelope(rast)),6) As clipper FROM aerials.boston WHERE rid = 6) As foo; xmax_w_trim | xmax_clipper | xmax_wo_trim | xmax_rast_orig ------------------+------------------+------------------+------------------ 230657.436173996 | 230657.436173996 | 230666.436173996 | 230666.436173996
![]() 裁剪前的完整栅格图块
|
![]() 裁剪后
|
-- Same example as before, but we need to set crop to false to be able to use ST_AddBand -- because ST_AddBand requires all bands be the same Width and height SELECT ST_AddBand(ST_Clip(rast, 1, ST_Buffer(ST_Centroid(ST_Envelope(rast)),20),false ), ARRAY[ST_Band(rast,2),ST_Band(rast,3)] ) from aerials.boston WHERE rid = 6;
![]() 裁剪前的完整栅格图块
|
![]() 剪裁后——超现实
|
-- Clip all bands of an aerial tile by a 20 meter buffer. -- Only difference is we don't specify a specific band to clip -- so all bands are clipped SELECT ST_Clip(rast, ST_Buffer(ST_Centroid(ST_Envelope(rast)), 20), false ) from aerials.boston WHERE rid = 4;
![]() 裁剪前的完整栅格图块
|
![]() 裁剪后
|