ST_Resize
Updated at:
Copy as MD
Resizes the pixel dimensions of a raster object while keeping its 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 pixel resampling and nodata handling. Defaults to ''. |
storageOption | cstring | A JSON string that controls how the output raster is stored. Defaults to ''. |
processExpr fields
| Field | Type | Default | Description |
|---|---|---|---|
resample | text | Near | The resampling algorithm. Valid values: Near, Average, Cubic, Bilinear. |
nodata | Boolean | false | Specifies whether to treat nodata pixels in the source raster as valid. If true, nodata pixels are preserved and not resampled. If false, nodata pixels are resampled. |
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 to assign a value per band. The array length must match the band count. |
UsenodataandnodataValuewith care. 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. Takes effect only when chunking is true. |
chunktable | String | '' | The name of the chunk table. By default, a temporary chunk table with a random name is created and is only valid in the current session. To persist the output raster across sessions, specify a non-empty name. |
compression | String | Same as source | The compression format. Valid values: None, JPEG, Zlib, PNG, LZO, LZ4. |
quality | Integer | Same as source | The image quality. Takes effect only when compression is JPEG. |
interleaving | String | Same as source | The band 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). |
IfchunktableisNULLor'', the output raster is stored in a temporary chunk table that is deleted when the session ends. To persist the output raster, setchunktableto a non-empty string.
Examples
The following examples resize a 512×512 raster to 1024×1024 using nearest-neighbor resampling and BSQ interleaving. All examples write the output to a permanent chunk table named result_rbt.
Setup
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', '{}')
);Resize with a permanent chunk table
Set chunktable in storageOption to save the output raster permanently.
CREATE TABLE rat_resize_result (id integer, rast raster);
-- No nodataValue: nodata handling disabled
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;
-- One nodataValue for all bands: nodata pixels preserved and assigned value 255
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;
-- Per-band nodataValue array: one value per band, nodata handling disabled
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;Resize with a temporary chunk table
Omit chunktable to store the output in a session-scoped temporary chunk table. Use this approach for intermediate computations that do not need to persist.
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;Is this page helpful?