This function clips a raster object.
Syntax
bytea ST_Clip(raster raster_obj,integer pyramidLevel, box extent, BoxType boxType);
bytea ST_Clip(raster raster_obj,integer pyramidLevel, box extent, BoxType boxType, integer destSrid);
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
Parameter | Description |
---|---|
raster_obj | The raster object. |
pyramidLevel | The pyramid level. |
extent | The area to be clipped, in the format of '((minX,minY),(maxX,maxY))' .
|
boxType | The coordinate type of the area to be clipped. Valid values:
|
destSrid | The spatial reference system identifier (SRID) of the output cell subset. |
geometry | The geometry object used for clipping. |
bands | The sequence numbers of bands to be clipped, in the format of '0-2' or '1,2,3' . The sequence number starts from 0. Default value: empty string ('' ). It indicates that all bands are to be clipped.
|
nodata | The array of NoData values in the format of float8[]. If the number of NoData values is fewer than the number of bands to be clipped, the predefined NoData value of a band is used to fill the area after the band is clipped. If a band has no predefined NoData value, the value 0 is used to fill the area after the band is clipped. |
clipOption | The clipping options. The value is a JSON-formatted string. |
The storage options for the output. The value is a JSON-formatted string. |
The following table describes the clipOption parameters.
Parameter | Type | Default value | Description |
---|---|---|---|
window_clip | BOOLEAN | false | Specifies whether to use the bounding box of the geometry object to clip the raster
object. Valid values:
|
rast_coord | BOOLEAN | false | Specifies whether the geometry object to clip is in raster coordinates. If true, the x coordinate of the geometry represents the column number and the y coordinate represents the row number. |
The following table describes fields in the storageOption parameters.
Parameter | Type | Default value | Description |
---|---|---|---|
compression | STRING | lz4 | The type of the compression algorithm. Valid values:
|
quality | INTEGER | 75 | The compression quality. This parameter takes effect only when the value of the compression parameter is set to jpeg. |
interleaving | STRING | Same as the original raster object | The interleaving type. Valid values:
|
endian | STRING | Same as the original raster object | The endian format. Valid values:
|
Description
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, you can use the ganos.raster.clip_max_buffer_size parameter to set the size of the cache.
Examples
Select ST_Clip(raster_obj, 0, '((128.980,30.0),(129.0,30.2))', 'World');
Select ST_Clip(raster_obj, 0, '((128.980,30.0),(129.0,30.2))', 'World', 4326);
-- Use a geometry object to clip a raster object.
-- Use the default clipping settings.
SELECT (ST_CLIP(rast, ST_geomfromtext('Polygon((0 0, 45 45, 90 45, 45 0, 0 0))', 4326), 0)).* from clip_table where id =1
-- Use white as the background color and compress the output into a PNG image.
SELECT (ST_CLIP(rast, ST_geomfromtext('Polygon((0 0, 45 45, 90 45, 45 0, 0 0))', 4326), 0, '', ARRAY[254,254,254], '', '{"compression":"png","interleaving":"bip"}')).* from clip_table where id =1;
-- Use the window of a geometry object to clip a raster object.
SELECT (ST_CLIP(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;