Resizes the pixel range of a raster object without changing its geospatial extent.
Syntax
raster ST_Resize(raster rast,
integer outWidth,
integer outHeight,
cstring processExpr default '',
cstring storageOption default '')Parameters
| Parameter | Description |
|---|---|
| rast | The raster object to resize. |
| outWidth | The width of the output raster object, in pixels. |
| outHeight | The height of the output raster object, in pixels. |
| processExpr | A JSON string that controls pixel resampling and nodata value handling. |
| storageOption | A JSON string that controls how the output raster object is stored. |
processExpr fields
Each key-value pair in the processExpr JSON string maps to a field described below.
| Field | Type | Default | Description |
|---|---|---|---|
| resample | text | Near | The resampling method. Valid values: Near, Average, Cubic, Bilinear. |
| nodata | Boolean | false | Specifies whether to treat nodata values in the source raster object as valid. If set to true, pixels with nodata values are not resampled. If set to false, pixels with nodata values are resampled. |
| nodataValue | float8 | float8[] | NULL | The nodata value to assign to bands in the output raster object. Specify one value to apply it to all bands, or specify one value per band. The number of values must match the number of bands. |
Note Set
nodata to false and omit nodataValue if the source raster object has no pixels with nodata values. Otherwise, image artifacts may occur.storageOption fields
| Field | Type | Default | Description |
|---|---|---|---|
| chunking | Boolean | Same as source | Specifies whether to store the output raster object as chunks. |
| chunkdim | String | Same as source | The chunk dimensions. Takes effect only when chunking is true. |
| chunktable | String | '' (empty string) | The name of the chunk table. If set to NULL or an empty string, the output is stored in a temporary chunk table with a random name, valid for the current session only. To persist the output, specify a permanent chunk table name. |
| compression | String | Same as source | The compression format. Valid values: None, JPEG, Zlib, PNG, LZO, LZ4. |
| quality | Integer | Same as source | The JPEG image quality. Takes effect only when compression is JPEG. |
| interleaving | String | Same as source | The interleaving type. Valid values: bip (band interleaved by pixel, BIP), bil (band interleaved by line, BIL), bsq (band sequential, BSQ). |
| endian | String | Same as source | The byte order. Valid values: NDR (little-endian), XDR (big-endian). |
Note If
chunktable is NULL or an empty string, the output is stored in a temporary chunk table that is deleted when the current session ends. Specify a chunk table name to save the output permanently.Examples
CREATE TABLE IF NOT EXISTS datasource_table(id integer, rast raster);
INSERT INTO datasource_table VALUES(1, ST_ImportFrom('rbt','$(RAST_DATA_DIR)/512_512_1_bsq_8u_geo.tif', '{}'));Method 1: Specify a permanent chunk table
Use a named chunktable to persist the output raster object.
CREATE TABLE rat_resize_result(id integer, rast raster);
-- No nodata field specified
INSERT INTO rat_resize_result(id, rast)
SELECT 10, ST_Resize(rast, 1024, 1024,
'{"resample":"Near","nodata":false}',
'{"chunking":true,"chunkdim":"(256,256,1)","compression":"none","interleaving":"bsq","chunktable":"result_rbt"}')
FROM datasource_table
WHERE id = 1;
-- Single nodata value applied to all bands; nodata pixels are not resampled
INSERT INTO rat_resize_result(id, rast)
SELECT 11, ST_Resize(rast, 1024, 1024,
'{"resample":"Near","nodata":true,"nodatavalue":255}',
'{"chunking":true,"chunkdim":"(256,256,1)","compression":"none","interleaving":"bsq","chunktable":"result_rbt"}')
FROM datasource_table
WHERE id = 1;
-- Multiple nodata values, one per band
INSERT INTO rat_resize_result(id, rast)
SELECT 12, ST_Resize(rast, 1024, 1024,
'{"resample":"Near","nodata":false,"nodatavalue":[255,255,255]}',
'{"chunking":true,"chunkdim":"(256,256,1)","compression":"none","interleaving":"bsq","chunktable":"result_rbt"}')
FROM datasource_table
WHERE id = 1;Method 2: Use a temporary chunk table
Omit chunktable to store the output in a session-scoped temporary table. The result is available for nested computations in the current session and is deleted when the session ends.
CREATE TEMP TABLE rat_resize_result_temp(id integer, rast raster);
INSERT INTO rat_resize_result_temp(id, rast)
SELECT 1, ST_Resize(rast, 1024, 1024,
'{"resample":"Near","nodata":false,"nodataValue":[255,255,255]}',
'{"chunking":true,"chunkdim":"(256,256,1)","compression":"none","interleaving":"bsq"}')
FROM datasource_table
WHERE id = 1;