Rescales the pixel dimensions of a raster object while keeping its geospatial extent unchanged. Returns the rescaled raster object.
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 equally to both the x and y directions. |
| processExpr | A JSON string that controls how pixels are resampled and how nodata values are handled. |
| storageOption | A JSON string that controls how the output raster object is stored. |
processExpr fields
| Field | Type | Default | Description |
|---|---|---|---|
| resample | text | Near | The resampling algorithm. Valid values: Near, Average, Cubic, Bilinear. |
| nodata | Boolean | false | Controls whether nodata values in the source raster are treated as valid. If true, pixels with nodata values are preserved and not resampled. If false, pixels with nodata values are resampled like normal pixels. |
| nodataValue | float8 or float8[] | NULL | Assigns new nodata values to the output raster's bands. Specify one value to apply it to all bands, or specify one value per band (the count must match the band count). |
Exercise caution when settingnodataandnodataValue. If the source raster has no pixels with nodata values, setnodatatofalseand omitnodataValue. Otherwise, image artifacts may occur.
storageOption fields
| Field | Type | Default | Description |
|---|---|---|---|
| chunking | Boolean | Same as source | 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 | Empty string ('') | The chunk table name. If set to NULL or an empty string (''), a temporary chunk table with a randomly generated name is created for the current session and deleted when the session ends. To persist the output raster beyond the current session, 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 image quality level. Takes effect only in JPEG format. |
| interleaving | String | Same as source | The interleaving format. 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). |
Examples
The examples below use datasource_table as the source table, which is loaded from a GeoTIFF file. Method 1 writes to a permanent chunk table; method 2 writes to a temporary chunk table valid only in the current session.
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: Write to a permanent chunk table
Specify chunktable to persist the output raster beyond the current session.
CREATE TABLE rat_rescale_result(id integer, rast raster);
-- Rescale without specifying a nodata value
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; pixels with nodata values are preserved
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 per-band nodata values
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;Method 2: Write to a temporary chunk table
Omit chunktable to write to a session-scoped temporary chunk table. Use this approach for intermediate computations within the same session.
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;该文章对您有帮助吗?