Name

ST_AddBand — 입력 인덱스 위치에 입력 초기값으로 추가된 입력 유형의 새 밴드(들)을 가진 래스터를 반환합니다. 인덱스를 설정하지 않을 경우, 마지막 위치에 밴드를 추가합니다.

Synopsis

(1) raster ST_AddBand(raster rast, addbandarg[] addbandargset);

(2) raster ST_AddBand(raster rast, integer index, text pixeltype, double precision initialvalue=0, double precision nodataval=NULL);

(3) raster ST_AddBand(raster rast, text pixeltype, double precision initialvalue=0, double precision nodataval=NULL);

(4) raster ST_AddBand(raster torast, raster fromrast, integer fromband=1, integer torastindex=at_end);

(5) raster ST_AddBand(raster torast, raster[] fromrasts, integer fromband=1, integer torastindex=at_end);

(6) raster ST_AddBand(raster rast, integer index, text outdbfile, integer[] outdbindex, double precision nodataval=NULL);

(7) raster ST_AddBand(raster rast, text outdbfile, integer[] outdbindex, integer index=at_end, double precision nodataval=NULL);

설명

입력 인덱스 위치에 입력 초기값, 입력 유형, 그리고 입력 NODATA 값의 새 밴드를 가진 래스터를 반환합니다. 인덱스를 설정하지 않을 경우, 마지막 위치에 밴드를 추가합니다. fromband 를 설정하지 않을 경우, 밴드 1로 가정합니다. 픽셀 유형은 ST_BandPixelType 에서 지정한 픽셀 유형들 가운데 하나의 문자열 표현식입니다. 만약 기존 인덱스를 설정할 경우, 해당 인덱스보다 크거나 같은 그 이후의 모든 밴드들의 인덱스가 1씩 증가합니다. 픽셀 유형의 최대값보다 큰 초기값을 설정할 경우, 해당 픽셀 유형이 가질 수 있는 가장 높은 값으로 초기값을 설정합니다.

addbandarg 의 배열을 입력받는 변종 1의 경우, 특정 addbandarg의 인덱스 값은 addbandarg가 묘사하는 밴드가 래스터에 추가될 당시의 해당 래스터에 상대적입니다. 다음에 나오는 복수의 새로운 밴드 예시를 참고하십시오.

래스터 배열을 입력받는 변종 5의 경우, torast 가 NULL이라면 배열 안에 있는 각 래스터의 fromband 밴드를 새 래스터에 누계(累計)합니다.

outdbfile 을 입력받는 변종 6 및 7의 경우, outdbfile 값이 래스터 파일을 가리키는 전체 경로를 포함해야만 합니다. PostgreSQL 서버 프로세스도 해당 파일에 접근할 수 있어야만 합니다.

개선 사항: 2.1.0 버전부터 addbandarg를 지원합니다.

개선 사항: 2.1.0 버전부터 새로운 DB 외부 밴드를 지원합니다.

예시: 새로운 단일 밴드

-- Add another band of type 8 bit unsigned integer with pixels initialized to 200
UPDATE dummy_rast
    SET rast = ST_AddBand(rast,'8BUI'::text,200)
WHERE rid = 1;
                
-- Create an empty raster 100x100 units, with upper left  right at 0, add 2 bands (band 1 is 0/1 boolean bit switch, band2 allows values 0-15)
-- uses addbandargs
INSERT INTO dummy_rast(rid,rast)
    VALUES(10, ST_AddBand(ST_MakeEmptyRaster(100, 100, 0, 0, 1, -1, 0, 0, 0),
    ARRAY[
        ROW(1, '1BB'::text, 0, NULL),
        ROW(2, '4BUI'::text, 0, NULL)
            ]::addbandarg[]
     )
    );

-- output meta data of raster bands to verify all is right --
SELECT  (bmd).*
FROM (SELECT ST_BandMetaData(rast,generate_series(1,2)) As bmd
    FROM dummy_rast WHERE rid = 10) AS foo;
 --result --
 pixeltype | nodatavalue | isoutdb | path
-----------+----------------+-------------+---------+------
 1BB       |             | f       |
 4BUI      |             | f       |


-- output meta data of raster -
SELECT  (rmd).width, (rmd).height, (rmd).numbands
FROM (SELECT ST_MetaData(rast) As rmd
    FROM dummy_rast WHERE rid = 10) AS foo;
-- result --
 upperleftx | upperlefty | width | height | scalex | scaley | skewx | skewy | srid | numbands
------------+------------+-------+--------+------------+------------+-------+-------+------+----------
          0 |          0 |   100 |    100 |      1 |     -1 |     0 |     0 |   0 |        2
                

예시: 복수의 새로운 밴드

SELECT
    *
FROM ST_BandMetadata(
    ST_AddBand(
        ST_MakeEmptyRaster(10, 10, 0, 0, 1, -1, 0, 0, 0),
        ARRAY[
            ROW(NULL, '8BUI', 255, 0),
            ROW(NULL, '16BUI', 1, 2),
            ROW(2, '32BUI', 100, 12),
            ROW(2, '32BF', 3.14, -1)
        ]::addbandarg[]
    ),
    ARRAY[]::integer[]
);

 bandnum | pixeltype | nodatavalue | isoutdb | path
---------+-----------+-------------+---------+------
       1 | 8BUI      |           0 | f       |
       2 | 32BF      |          -1 | f       |
       3 | 32BUI     |          12 | f       |
       4 | 16BUI     |           2 | f       |
                
-- Aggregate the 1st band of a table of like rasters into a single raster
-- with as many bands as there are test_types and as many rows (new rasters) as there are mice
-- NOTE: The ORDER BY test_type is only supported in PostgreSQL 9.0+
-- for 8.4 and below it usually works to order your data in a subselect (but not guaranteed)
-- The resulting raster will have a band for each test_type alphabetical by test_type
-- For mouse lovers: No mice were harmed in this exercise
SELECT
    mouse,
    ST_AddBand(NULL, array_agg(rast ORDER BY test_type), 1) As rast
FROM mice_studies
GROUP BY mouse;
                

예시: 새로운 DB 외부 밴드

SELECT
    *
FROM ST_BandMetadata(
    ST_AddBand(
        ST_MakeEmptyRaster(10, 10, 0, 0, 1, -1, 0, 0, 0),
        '/home/raster/mytestraster.tif'::text, NULL::int[]
    ),
    ARRAY[]::integer[]
);

 bandnum | pixeltype | nodatavalue | isoutdb | path
---------+-----------+-------------+---------+------
       1 | 8BUI      |             | t       | /home/raster/mytestraster.tif
       2 | 8BUI      |             | t       | /home/raster/mytestraster.tif
       3 | 8BUI      |             | t       | /home/raster/mytestraster.tif
                

참고

ST_BandMetaData, ST_BandPixelType, ST_MakeEmptyRaster, ST_MetaData, ST_NumBands, ST_Reclass