このトピックでは、ST_Transform関数について説明します。 この関数は、ラスターオブジェクトの基本座標を既知の空間参照系から別のものに変換します。
構文
raster ST_Transform(raster rast,
integer outSrid,
cstring processexpr default '',
cstring storageOption default '')
パラメーター
パラメーター | 説明 |
rast | 座標を変換する元のラスターオブジェクト。 |
outSrid | 新しいラスタオブジェクトの空間参照システム。 このパラメーターの値は、spatial_ref_sysテーブルから照会できる有効なSIRDである必要があります。 |
processExpr | ピクセルをリサンプリングし、nodata値を処理する方法を指定するJSON文字列。 |
storageOption | 新しいラスターオブジェクトを格納する方法を指定するJSON文字列。 |
processExprパラメーターで指定されたJSON文字列の各子JSONオブジェクトは、フィールドを表します。 次の表に、これらのフィールドを示します。
フィールド | 説明 | データ型 | デフォルト値 | 設定ノート |
resample | ピクセルを再サンプリングするために使用される方法。 | Text | Near | 有効な値: Near | Average | Cubic | Bilinear。 |
nodata | 元のラスタオブジェクトのnodata値が有効かどうかを指定します。 | Boolean | false |
|
nodataValue | 新しいラスタオブジェクトのバンドに基づいて指定された新しいnodata値。 | float8 float8[] | NULL | nodataValueフィールドで1つ以上のnodata値を指定できます。
|
nodataフィールドとnodataValueフィールドを指定するときは注意してください。 元のラスターオブジェクトにnodata値を持つピクセルがない場合は、nodataフィールドをfalseに設定し、nodataValueフィールドを指定しないことを推奨します。 さもなければ、画像アーチファクトが発生し得る。
次の表に、storageOptionパラメーターのフィールドを示します。
フィールド | 説明 | データ型 | デフォルト値 | 設定ノート |
chunking | 新しいラスターオブジェクトをチャンクとして保存するかどうかを指定します。 | Boolean | Same as the original raster object | N/A |
chunkdim | 新しいラスタオブジェクトをチャンクとして格納するために使用されるディメンション。 | String | Same as the original raster object | このフィールドは、チャンキングフィールドがtrueに設定されている場合にのみ有効です。 |
chunktable | チャンクテーブルの名前です。 | String | Null string ('') | デフォルトでは、データを格納するためにランダムな名前の一時チャンクテーブルが生成されます。 この一時チャンクテーブルは、現在のセッションでのみ有効です。 新しいラスターオブジェクトを永続的に保存するには、chunktableフィールドでチャンクテーブルの名前を指定する必要があります。 |
compression | 画像圧縮に使用される形式。 | String | Same as the original raster object | None、JPEG、Zlib、PNG、LZO、LZ4の6つの圧縮形式がサポートされています。 |
quality | 新しいラスターオブジェクトの画質。 | Integer | Same as the original raster object | このフィールドはJPEG形式でのみ有効です。 |
interleaving | 新しいラスタオブジェクトのインターリーブタイプ。 | String | Same as the original raster object | 有効な値:
|
endian | 新しいラスタオブジェクトのエンディアン形式。 | String | Same as the original raster object | 有効な値:
|
chunktableフィールドをNULLまたはnull文字列 ('') に設定すると、現在のセッションでランダムな名前の一時チャンクテーブルが生成され、新しいラスターオブジェクトが格納されます。 一時チャンクテーブルは現在のセッションでのみ有効であり、現在のセッションが終了した直後に削除されます。 新しいラスターオブジェクトを永続的に保存するには、chunktableフィールドに永続チャンクテーブルを作成するように指定する必要があります。
例
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: Specify the chunktable field to create a permanent chunk table for storing the new raster object.
----------------------------------------------------
CREATE TABLE rat_transform_result(id integer, rast raster);
-- If you do not specify the nodata field:
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;
-- If you specify one nodata value in the nodataValue field and pixels with nodata values are resampled:
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;
-- If you specify more than one nodata value in the nodataValue field:
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;
----------------------------------------------------
-- Method 2: Do not specify the chunktable field. The new raster object is saved to a temporary chunk table with a random name and can only be used for nested computations in the current session.
----------------------------------------------------
CREATE TEMP TABLE rat_transform_result_temp(id integer, rast raster);
INSERT INTO rast_clip_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;