ST_AddBand — Повертає растр з новим каналом (каналами) заданого типу, доданим із заданим початковим значенням у заданому місці індексу. Якщо індекс не вказано, діапазон додається в кінець.
(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), значення повинно містити повний шлях до растрового файлу. Файл також повинен бути доступним для процесу сервера postgres.
Покращено: додано підтримку addbandarg 2.1.0.
Покращено: додано підтримку 2.1.0 для нових діапазонів out-db.
Single New Band.
This example adds another 8-bit unsigned integer band 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.
Output metadata for the raster bands to verify they are correct.
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[]
)
);
SELECT (bmd).*
FROM (SELECT ST_BandMetaData(rast, generate_series(1, 2)) As bmd
FROM dummy_rast WHERE rid = 10) AS foo;
pixeltype | nodatavalue | isoutdb | path -----------+----------------+-------------+---------+------ 1BB | | f | 4BUI | | f |
This example outputs metadata for the raster.
SELECT (rmd).width, (rmd).height, (rmd).numbands
FROM (SELECT ST_MetaData(rast) As rmd
FROM dummy_rast WHERE rid = 10) AS foo;
width | height | numbands -------+--------+---------- 100 | 100 | 2
Multiple New Bands.
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 | outdbbandnum | filesize | filetimestamp
---------+-----------+-------------+---------+------+--------------+----------+---------------
1 | 8BUI | 0 | f | null | null | null | null
2 | 32BF | -1 | f | null | null | null | null
3 | 32BUI | 12 | f | null | null | null | null
4 | 16BUI | 2 | f | null | null | null | null
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 that The ORDER BY test_type clause relies on aggregate ORDER BY support. 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;
New Out-db band.
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