Resizes the pixel dimensions of a raster object to a new width and height while keeping the geospatial extent unchanged.
Syntax
raster ST_Resize(raster rast,
integer outWidth,
integer outHeight,
cstring processExpr default '',
cstring storageOption default '')Parameters
| Parameter | Type | Description |
|---|---|---|
rast | raster | The source raster object to resize. |
outWidth | integer | The width of the output raster, in pixels. |
outHeight | integer | The height of the output raster, in pixels. |
processExpr | cstring | A JSON string that controls resampling and nodata handling. Defaults to an empty string. |
storageOption | cstring | A JSON string that controls how the output raster is stored. Defaults to an empty string. |
processExpr fields
| Field | Type | Default | Description |
|---|---|---|---|
resample | text | Near | The resampling algorithm. Valid values: Near, Average, Cubic, Bilinear. |
nodata | Boolean | false | Specifies whether nodata values in the source raster are treated as valid. If true, pixels with nodata values are preserved and not resampled. If false, they are resampled like normal pixels. |
nodataValue | float8 or float8[] | NULL | The nodata value to assign in the output raster. Specify a single value to apply it to all bands, or an array whose length matches the number of bands. |
If the source raster has no nodata pixels, setnodatatofalseand omitnodataValue. Otherwise, image artifacts may occur.
storageOption fields
| Field | Type | Default | Description |
|---|---|---|---|
chunking | Boolean | Same as source | Specifies whether to store the output raster as chunks. |
chunkdim | String | Same as source | The chunk dimensions, for example (256,256,1). Takes effect only when chunking is true. |
chunktable | String | '' (empty) | The name of the chunk table. If left blank or NULL, a temporary chunk table with a random name is created for the current session and deleted when the session ends. Specify a name to create a permanent chunk table. |
compression | String | Same as source | The compression format. Valid values: None, JPEG, Zlib, PNG, LZO, LZ4. |
quality | Integer | Same as source | The JPEG quality level. Takes effect only when compression is JPEG. |
interleaving | String | Same as source | The interleaving type: bip (band interleaved by pixel, BIP), bil (band interleaved by line, BIL), or bsq (band sequential, BSQ). |
endian | String | Same as source | The byte order: NDR (little endian) or XDR (big endian). |
IfchunktableisNULLor an empty string, the output raster is stored in a session-only temporary chunk table. The table is deleted when the session ends. To persist the output across sessions, specify a chunk table name inchunktable.
Examples
The following examples resize a 512x512 raster to 1024x1024 pixels using nearest neighbor resampling. All examples that write to a permanent chunk table use result_rbt as the chunk table name.
First, set up the source data:
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', '{}')
);
CREATE TABLE rat_resize_result (id integer, rast raster);Example 1: Resize without nodata handling
Use this when the source raster has no nodata pixels.
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;Example 2: Resize with a single nodata value
Pixels with nodata values are preserved, and a nodata value of 255 is assigned to all bands in the output.
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;Example 3: Resize with per-band nodata values
Specify one nodata value per band. The array length must match the number of bands in the output raster.
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;Example 4: Resize to a session-only temporary raster
Omit chunktable to store the output in a temporary chunk table. The result is available only within the current session and is useful for intermediate computations.
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;