Name

ST_Clip — 返回由输入几何图形剪裁的栅格。如果未指定波段编号,则处理所有波段。如果 crop 未指定或为TRUE,则将裁剪输出栅格。

Synopsis

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值,则结果栅格的nodata值将设置为ST_MinPossibleValue(ST_BandPixelType(Rast,Band))。当数组中的nodata值的数量小于频带数时,数组中的最后一个用于剩余的频段。如果无数据值的数量大于频带的数量,则忽略额外的无数据值。接受nodata值数组的所有变体也接受将分配给每个波段的单个值。

如果 crop 如果未指定,则假定为True,这意味着输出栅格将被裁剪到 geomrast 范围。如果 crop 设置为FALSE,则新栅格的范围与 rast

可用性:2.0.0

增强版:2.1.0用C重写

此处的示例使用MassGIS站点上提供的马萨诸塞州航测数据 MassGIS航空正射影像 。坐标以马萨诸塞州平面米为单位。

示例:1波段裁剪

-- 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
                    

裁剪前的完整栅格平铺

剪裁后

示例:1不裁剪波段并原封不动地添加回其他波段

-- 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;
                    

裁剪前的完整栅格平铺

剪裁后

另请参阅

ST_AddBand, ST_MapAlgebra(回调函数版本), ST_Intersection