ST_CreateRast

更新时间:
复制 MD 格式

Creates a raster object from an Object Storage Service (OSS) object, a MinIO object, a Hadoop Distributed File System (HDFS) file, or a one-dimensional array.

Syntax

raster ST_CreateRast(cstring url);
raster ST_CreateRast(cstring url, cstring storageOption);
raster ST_CreateRast(anyarray data, integer width, cstring storageOption, geometry extent);

Parameters

ParameterDescription
urlThe path of the source object. For supported URL formats and protocols, see Object storage paths.
storageOptionA JSON string that defines the chunk layout for storing the raster pyramid. For supported fields, see storageOption fields.
createOptionA JSON string that controls band statistics calculation during import. For supported fields, see createOption fields.
dataRaster data as a one-dimensional array. The number of elements must equal the number of columns multiplied by the number of rows.
widthThe number of columns in the raster data.
extent(Optional) The spatial extent of the raster, represented as a geometry.

storageOption fields

FieldTypeFormatDefaultDescription
chunkdimstring(w,h,b)Same as the source objectThe chunk dimensions for storing raster data.
interleavingstringbsqThe band interleaving method. Valid values: bip (band interleaved by pixel, BIP), bil (band interleaved by line, BIL), bsq (band sequential, BSQ), auto (selected automatically).
chunk_tablestringNoneThe name of the chunk table. Required when generating a raster object from an array.

Note Change chunkdim or interleaving only when necessary:

  • Change interleaving to bip when users need multiband RGB combination rendering and the current value is bsq.

  • Change chunkdim when the source image has chunks of 1×n pixels but you need 256×256 chunks.

createOption fields

FieldTypeDefaultDescription
compute_statsbooleanfalseSpecifies whether to automatically calculate band statistics during import.
approxbooleanfalseSpecifies whether to use sampling to calculate statistics. If set to true, results may be less accurate.
factorinteger4The sampling factor. A value of n means each sampling unit covers n pixels. Takes effect only when approx is true.
exclusive_nodatabooleantrueSpecifies whether to exclude nodata values from statistics calculations.

Usage notes

URL format

The URL format for OSS objects is oss://access_id:secret_key@Endpoint/path_to/file. The endpoint is optional — if omitted, the system resolves it automatically, but the path must start with a forward slash (/).

The endpoint is the domain name used to access the OSS bucket. For best import performance, deploy your AnalyticDB for PostgreSQL instance in the same region as the OSS bucket. For more information, see s.

Supported protocols

ProtocolURL formatExample
OSSOSS://<ak>:<ak_secret>@<endpoint>/<bucket>/<path>OSS://<ak>:<ak_secret>@oss-cn-beijing-internal.aliyuncs.com/mybucket/data/image.tif
MinIOMIO://<ak>:<ak_secret>@<host>:<port>/<bucket>/<path>MIO://<ak>:<ak_secret>@10.0.0.1:443/mybucket/data/image.tif
HDFSHDFS://<user_name>@<host>:<port>/<path>HDFS://<user_name>@10.0.0.1:8020/path/image.tif

Examples

Create a raster object from an OSS object

Specify the AccessKey ID, AccessKey secret, and endpoint in the URL.

SELECT ST_CreateRast('OSS://<ak>:<ak_secret>@oss-cn-beijing-internal.aliyuncs.com/mybucket/data/image.tif');

Create a raster object from a MinIO object

Specify the host and port in the URL.

SELECT ST_CreateRast('MIO://<ak>:<ak_secret>@10.0.0.1:443/mybucket/data/image.tif');

Create a raster object from an HDFS file

Specify the username in the URL.

SELECT ST_CreateRast('HDFS://<user_name>@10.0.0.1:8020/path/image.tif');

Set chunk dimensions and band interleaving

Use storageOption to override the default chunk layout.

SELECT ST_CreateRast(
  'OSS://<ak>:<ak_secret>@oss-cn-beijing-internal.aliyuncs.com/mybucket/data/image.tif',
  '{"chunkdim":"(256,256,3)","interleaving":"auto"}'
);

Calculate band statistics during import

Pass createOption with compute_stats set to true.

SELECT ST_CreateRast(
  'OSS://<ak>:<ak_secret>@oss-cn-beijing-internal.aliyuncs.com/mybucket/data/image.tif',
  '{"chunkdim":"(256,256,3)","interleaving":"auto"}',
  '{"compute_stats":true}'
);

Create a raster object from a NetCDF image with subsets

Append the subset name after a colon (:) at the end of the URL.

SELECT ST_CreateRast('OSS://<ak>:<ak_secret>@oss-cn-beijing-internal.aliyuncs.com/mybucket/data/image.nc:hcc');

Create a raster object from an HDF5 image with subsets

Append the dataset path after :// at the end of the URL.

SELECT ST_CreateRast('OSS://<ak>:<ak_secret>@oss-cn-beijing-internal.aliyuncs.com/mybucket/data/image.hdf5://ds/hcc');

Create a raster object from an array

Pass a one-dimensional array, the number of columns, a storageOption with chunk_table specified, and an optional geometry extent.

SELECT ST_FixedRid(
  ST_CreateRast(
    ARRAY[10, 11, 8, 12],
    2,
    '{"chunktable":"rbt"}',
    ST_GeomFromText('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))', 4326)
  )
);

Aggregate records into a raster object

Use array_agg to collect values from a table before passing them to ST_CreateRast.

SELECT ST_FixedRid(
  ST_CreateRast(
    (SELECT array_agg(value) FROM point_table),
    300,
    '{"chunktable":"rbt"}'
  )
);