All Products
Search
Document Center

AnalyticDB:ST_Clip

Last Updated:Mar 28, 2026

Clips a raster object by a bounding box or a geometry object. By default, all bands are clipped. If no NoData value is specified, the predefined NoData value of each band is used; if no predefined value exists, 0 fills the clipped area.

Syntax

-- Overload 1: clip by bounding box
bytea ST_Clip(raster raster_obj, integer pyramidLevel, box extent, BoxType boxType);

-- Overload 2: clip by bounding box and reproject output
bytea ST_Clip(raster raster_obj, integer pyramidLevel, box extent, BoxType boxType, integer destSrid);

-- Overload 3: clip by geometry object
record ST_Clip(raster raster_obj,
               geometry geom,
               integer pyramidLevel default 0,
               cstring bands default '',
               float8[] nodata default NULL,
               cstring clipOption default '',
               cstring storageOption default '',
               out box outwindow,
               out bytea rasterblob)

Parameters

ParameterTypeDescription
raster_objrasterThe raster object to clip.
pyramidLevelintegerThe pyramid level.
extentboxThe area to clip. Format: '((minX,minY),(maxX,maxY))'.
boxTypeBoxTypeThe coordinate type of the clipping area. Valid values: Raster (pixel coordinates), World (world coordinates).
destSridintegerThe spatial reference system identifier (SRID) of the output cell subset.
geomgeometryThe geometry object used to clip the raster.
bandscstringThe band sequence numbers to clip. Format: '0-2' or '1,2,3'. Sequence numbers start from 0. Default: '' (all bands).
nodatafloat8[]NoData values for the clipped area, one per band. If the array contains fewer values than the number of bands, the predefined NoData value of each remaining band is used. If a band has no predefined NoData value, 0 is used.
clipOptioncstringClipping options. See clipOption fields.
storageOptioncstringStorage options for the output. See storageOption fields.
outwindowboxOutput parameter. The size of the returned raster object.
rasterblobbyteaOutput parameter. The binary pixel matrix.

clipOption fields

FieldTypeDefaultDescription
window_clipboolfalseWhether to clip using the bounding box of the geometry object instead of the geometry itself. true uses the minimum bounding rectangle (MBR); false uses the geometry shape.
rast_coordboolfalseWhether the geometry is in raster coordinates. When true, the x coordinate represents the column number and the y coordinate represents the row number, both starting from 0.

storageOption fields

FieldTypeDefaultDescription
compressionstringlz4Compression algorithm for the output. Valid values: none, jpeg, zlib, png, lzo, lz4.
qualityinteger75Compression quality. Applies only when compression is jpeg.
interleavingstringSame as the source rasterInterleaving type. Valid values: bip (band interleaved by pixel), bil (band interleaved by line), bsq (band sequential).
endianstringSame as the source rasterByte order of the output. Valid values: NDR (little-endian), XDR (big-endian).

Usage notes

The default clipping cache is 100 MB, which indicates that only 100 MB of data can be returned. To adjust the limit on the output size, set the ganos.raster.clip_max_buffer_size parameter.

Examples

Clip by world coordinates (bounding box)

Clips a raster object at pyramid level 0 using a world-coordinate bounding box.

DO $$
DECLARE
    rast raster;
BEGIN
    SELECT raster_obj INTO rast FROM raster_table WHERE id = 1;
    SELECT ST_Clip(rast, 0, '((128.980,30.0),(129.0,30.2))', 'World');
END;
$$ LANGUAGE 'plpgsql';

Clip by geometry object (all bands)

Clips all bands of a raster object using a geometry object. The output window and binary pixel data are returned as separate fields.

SELECT outwindow, rasterblob
FROM ST_Clip(
    rast,
    ST_GeomFromText('POLYGON((128.98 30.0, 129.0 30.0, 129.0 30.2, 128.98 30.2, 128.98 30.0))'),
    0,       -- pyramid level
    '',      -- all bands
    NULL,    -- use predefined NoData values
    '',      -- default clip options
    ''       -- default storage options
);

Clip by geometry object with custom options

Clips band 0 only, fills the clipped area with NoData value 0, and uses the MBR of the geometry instead of the geometry shape.

SELECT outwindow, rasterblob
FROM ST_Clip(
    rast,
    ST_GeomFromText('POLYGON((128.98 30.0, 129.0 30.0, 129.0 30.2, 128.98 30.2, 128.98 30.0))'),
    0,                          -- pyramid level
    '0',                        -- band 0 only
    ARRAY[0.0]::float8[],       -- NoData value for the clipped area
    '{"window_clip": true}',    -- use MBR of the geometry
    '{"compression": "lz4"}'    -- lz4 compression
);