Rescales the pixel range of a raster object by adjusting its resolution. The geospatial extent remains unchanged.
Syntax
raster ST_Rescale(raster rast,
f8 scale_x,
f8 scale_y,
cstring processexpr default '',
cstring storageOption default '');
raster ST_Rescale(raster raster,
f8 scale_xy,
cstring processexpr default '',
cstring storageOption default '')Parameters
| Parameter | Description |
|---|---|
rast | The raster object to rescale. |
scale_x | The scale ratio in the x direction. |
scale_y | The scale ratio in the y direction. |
scale_xy | The scale ratio applied uniformly to both x and y directions. |
processexpr | A JSON string that controls resampling behavior and nodata handling. Defaults to '' (uses default values for all fields). See processexpr fields. |
storageOption | A JSON string that controls how the output raster is stored. Defaults to '' (inherits settings from the input raster). See storageOption fields. |
processexpr fields
| Field | Type | Default | Description |
|---|---|---|---|
resample | text | Near | Resampling algorithm. Valid values: Near, Average, Cubic, Bilinear. |
nodata | Boolean | false | Specifies whether nodata values are treated as valid. If true, pixels with nodata values are not resampled. If false, they are resampled. |
nodataValue | float8 or float8[] | NULL | The nodata value(s) to assign in the output raster. Specify a single value to apply to all bands, or one value per band (the count must match the number of bands in the output raster). |
Set nodata to false and omit nodataValue if the input raster has no nodata pixels. Specifying these fields unnecessarily can cause image artifacts.
storageOption fields
| Field | Type | Default | Description |
|---|---|---|---|
chunking | Boolean | Same as input | Specifies whether to store the output raster as chunks. |
chunkdim | String | Same as input | Chunk dimensions. Takes effect only when chunking is true. |
chunktable | String | '' | The name of the chunk table for the output raster. If set to NULL or '', a temporary chunk table with a random name is created and is valid only for the current session. To retain the output raster permanently, specify a table name. |
compression | String | Same as input | Compression format. Valid values: None, JPEG, Zlib, PNG, LZO, LZ4. |
quality | Integer | Same as input | Image quality. Takes effect only when compression is JPEG. |
interleaving | String | Same as input | Interleaving type. Valid values: bip (band interleaved by pixel, BIP), bil (band interleaved by line, BIL), bsq (band sequential, BSQ). |
endian | String | Same as input | 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. Specify a permanent chunk table name to persist the output across sessions.
Examples
The following examples use a 512x512 single-band raster imported from a GeoTIFF file and rescale it to 1024x1024 pixels.
-- Set up the source table
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', '{}')
);Store output in a permanent chunk table
Specify chunktable in storageOption to retain the output raster after the session ends.
CREATE TABLE rat_rescale_result (id integer, rast raster);
-- Rescale with default nodata handling (nodata field omitted, uses default false)
INSERT INTO rat_rescale_result (id, rast)
SELECT 10, ST_Rescale(
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;
-- Rescale with a single nodata value; nodata pixels are not resampled
INSERT INTO rat_rescale_result (id, rast)
SELECT 11, ST_Rescale(
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;
-- Rescale with one nodata value per band; nodata pixels are resampled
INSERT INTO rat_rescale_result (id, rast)
SELECT 12, ST_Rescale(
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;Use a temporary chunk table for in-session computation
Omit chunktable to store the output in a session-scoped temporary table. The output is available for nested computations within the current session but is discarded when the session ends.
CREATE TEMP TABLE rat_rescale_result_temp (id integer, rast raster);
INSERT INTO rat_rescale_result_temp (id, rast)
SELECT 1, ST_Rescale(
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;