This topic describes the ST_Clip function. 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 that you want to clip. The value is in the format of |
boxType | The coordinate type of the area that you want to clip. Valid values:
|
destSrid | The spatial reference system identifier (SRID) of the output cell subset. |
geom | The geometry object that you want to clip. |
bands | The sequence numbers of bands to be clipped, in the format of |
nodata | The array of NoData values in the format of float8[]. If the number of the NoData values is less than the number of the 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 option. |
The storage option for the output. | |
outwindow | The size of the returned raster object. |
rasterblob | The binary pixel matrix. |
The following table describes the fields of the clipOption parameter.
Field | Type | Default value | Description |
window_clip | bool | false | Specifies whether to use the bounding box of the geometry object to clip the raster object. Valid values:
|
rast_coord | bool | false | Specifies whether the geometry object that you want to clip is in raster coordinates. If the geometry object that you want to clip is in raster coordinates, the x coordinate of the geometry represents the column number and the y coordinate represents the row number. The column number and row number start from 0. |
The following table describes fields of the storageOption parameter.
Field | 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 | The interleaving type. Valid values:
|
endian | string | Same as the original raster | 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') from clip_table;
Select ST_Clip(raster_obj, 0, '((128.980,30.0),(129.0,30.2))', 'World', 4326) from clip_table;
-- 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;