Reprojects a raster object from one spatial reference system (SRS) to another, transforming the underlying coordinates and resampling pixel values accordingly.
Syntax
raster ST_Transform(raster rast,
integer outSrid,
cstring processExpr default '',
cstring storageOption default '')Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
rast | raster | — | The source raster object to reproject. |
outSrid | integer | — | The SRID of the target spatial reference system. Must be a valid SRID in the spatial_ref_sys table. |
processExpr | cstring | '' | JSON string controlling the resampling algorithm and nodata handling. |
storageOption | cstring | '' | JSON string controlling how the output raster is stored. |
processExpr fields
| Field | Type | Default | Description |
|---|---|---|---|
resample | Text | Near | Resampling algorithm. Valid values: Near, Average, Cubic, Bilinear. |
nodata | Boolean | false | Specifies whether nodata values in the source raster are treated as valid. If true, pixels with nodata values are not resampled. If false, those pixels are resampled. |
nodataValue | float8 or float8[] | NULL | Nodata value to assign to the output raster. Specify a single value to apply it to all bands, or an array of values—one per band. The array length must match the number of bands. |
Warning
Use nodata and nodataValue with care. If the source raster has no nodata pixels, set nodata to false and omit nodataValue. Misconfiguring these fields can introduce image artifacts.
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 | Chunk dimensions. Takes effect only when chunking is true. |
chunktable | String | '' | Name of the chunk table for the output raster. If set to NULL or an empty string, a temporary chunk table with a random name is created and exists only for the current session. To persist the output raster beyond the session, specify a table name. |
compression | String | Same as source | Compression format. Valid values: None, JPEG, Zlib, PNG, LZO, LZ4. |
quality | Integer | Same as source | Image quality level. Takes effect only when compression is JPEG. |
interleaving | String | Same as source | Pixel 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 | Byte order. NDR for little-endian, XDR for big-endian. |
Examples
All examples reproject a raster from its source SRS to EPSG:32652 using nearest-neighbor resampling.
-- Set up the source data
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', '{}'));Persist the output to a permanent chunk table
Specify a chunktable name to save the output raster across sessions.
CREATE TABLE rat_transform_result (id integer, rast raster);
-- Without nodata handling
INSERT INTO rat_transform_result (id, rast)
SELECT 10, ST_Transform(
rast,
32652,
'{"resample":"Near","nodata":false}',
'{"chunking":true,"chunkdim":"(256,256,1)","compression":"none","interleaving":"bsq","chunktable":"result_rbt"}'
)
FROM datasource_table
WHERE id = 1;
-- With nodata enabled and a single nodata value (applies to all bands)
INSERT INTO rat_transform_result (id, rast)
SELECT 11, ST_Transform(
rast,
32652,
'{"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;
-- With multiple nodata values (one per band)
INSERT INTO rat_transform_result (id, rast)
SELECT 12, ST_Transform(
rast,
32652,
'{"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 temporary chunk table. The table is deleted when the session ends.
CREATE TEMP TABLE rat_transform_result_temp (id integer, rast raster);
INSERT INTO rat_transform_result_temp (id, rast)
SELECT 1, ST_Transform(
rast,
32652,
'{"resample":"Near","nodata":false,"nodataValue":[255,255,255]}',
'{"chunking":true,"chunkdim":"(256,256,1)","compression":"none","interleaving":"bsq"}'
)
FROM datasource_table
WHERE id = 1;该文章对您有帮助吗?