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

ParameterTypeDescription
rastrasterThe source raster object to resize.
outWidthintegerThe width of the output raster, in pixels.
outHeightintegerThe height of the output raster, in pixels.
processExprcstringA JSON string that controls pixel resampling and nodata handling. Defaults to ''.
storageOptioncstringA JSON string that controls how the output raster is stored. Defaults to ''.

processExpr fields

FieldTypeDefaultDescription
resampletextNearThe resampling algorithm. Valid values: Near, Average, Cubic, Bilinear.
nodataBooleanfalseSpecifies 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.
nodataValuefloat8 or float8[]NULLThe 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.
Use nodata and nodataValue with care. If the source raster has no nodata pixels, set nodata to false and omit nodataValue. Otherwise, image artifacts may occur.

storageOption fields

FieldTypeDefaultDescription
chunkingBooleanSame as sourceSpecifies whether to store the output raster as chunks.
chunkdimStringSame as sourceThe chunk dimensions. Takes effect only when chunking is true.
chunktableString''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.
compressionStringSame as sourceThe compression format. Valid values: None, JPEG, Zlib, PNG, LZO, LZ4.
qualityIntegerSame as sourceThe image quality. Takes effect only when compression is JPEG.
interleavingStringSame as sourceThe band interleaving type. Valid values: bip (band interleaved by pixel, BIP), bil (band interleaved by line, BIL), bsq (band sequential, BSQ).
endianStringSame as sourceThe byte order. Valid values: NDR (little endian), XDR (big endian).
If chunktable is NULL or '', the output raster is stored in a temporary chunk table that is deleted when the session ends. To persist the output raster, set chunktable to 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;