ST_Rescale

更新时间:
复制 MD 格式

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

ParameterDescription
rastThe raster object to rescale.
scale_xThe scale ratio in the x direction.
scale_yThe scale ratio in the y direction.
scale_xyThe scale ratio applied equally to both the x and y directions.
processExprA JSON string that controls how pixels are resampled and how nodata values are handled.
storageOptionA JSON string that controls how the output raster object is stored.

processExpr fields

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

storageOption fields

FieldTypeDefaultDescription
chunkingBooleanSame as sourceWhether to store the output raster as chunks.
chunkdimStringSame as sourceThe chunk dimensions. Takes effect only when chunking is true.
chunktableStringEmpty 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.
compressionStringSame as sourceThe compression format. Valid values: None, JPEG, Zlib, PNG, LZO, LZ4.
qualityIntegerSame as sourceThe image quality level. Takes effect only in JPEG format.
interleavingStringSame as sourceThe interleaving format. 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).

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;