Назва

ST_Band — Повертає один або декілька каналів існуючого растру як новий растр. Корисно для створення нових растрів на основі існуючих.

Короткий огляд

raster ST_Band(raster rast, integer[] nbands = ARRAY[1]);

raster ST_Band(raster rast, integer nband);

raster ST_Band(raster rast, text nbands, character delimiter=,);

Description

Повертає один або декілька каналів існуючого растра як новий растр. Корисно для створення нових растрів з існуючих растрів або експорту лише вибраних каналів растра, або для зміни порядку каналів у растрі. Якщо канал не вказано або будь-який із вказаних каналів не існує в растрі, то повертаються всі канали. Використовується як допоміжна функція в різних функціях, наприклад для видалення каналів.

[Застереження]

Для nbands як текстового варіанту функції, роздільником за замовчуванням є ,, що означає, що ви можете запитувати '1,2,3', а якщо ви хочете використовувати інший роздільник, ви повинні ввести ST_Band(rast, '1@2@3', '@'). Для запиту декількох каналів ми настійно рекомендуємо використовувати масивну форму цієї функції, наприклад ST_Band(rast, '{1,2,3}'::int[]);, оскільки форма text списку смуг може бути видалена в майбутніх версіях PostGIS.

Доступність: 2.0.0

Приклади

This example creates two rasters: one containing band 1 of dummy_rast, and one containing band 2 reclassified as 2BUI.

Code
SELECT ST_NumBands(rast1) As numb1, ST_BandPixelType(rast1) As pix1,
 ST_NumBands(rast2) As numb2, ST_BandPixelType(rast2) As pix2
FROM (
    SELECT ST_Band(rast) As rast1, ST_Reclass(ST_Band(rast, 3), '100-200):1, [200-254:2', '2BUI') As rast2
        FROM dummy_rast
        WHERE rid = 2) As foo;
Вивід растрових зображень
numb1 | pix1 | numb2 | pix2
-------+------+-------+------
     1 | 8BUI |     1 | 2BUI

Return bands 2 and 3 using array cast syntax.

Code
SELECT ST_NumBands(ST_Band(rast, '{2,3}'::int[])) As num_bands
FROM dummy_rast WHERE rid=2;
Вивід растрових зображень
2

Return bands 2 and 3 using array syntax.

Code
SELECT ST_NumBands(ST_Band(rast, ARRAY[2, 3])) As num_bands
    FROM dummy_rast
WHERE rid=2;
                    
Вивід растрових зображень
2

This example uses three distinct shapes as the red, green, and blue bands of a synthetic raster. It compares the original RGB raster with band 2 followed by band 1 twice, and with band 3 alone.

Code
WITH canvas AS (
    SELECT ST_AddBand(
        ST_AddBand(
            ST_AddBand(
                ST_MakeEmptyRaster(128, 128, 0, 128, 1, -1, 0, 0, 0),
                '8BUI'::text, 0::double precision, 0::double precision
            ),
            '8BUI'::text, 0::double precision, 0::double precision
        ),
        '8BUI'::text, 0::double precision, 0::double precision
    ) AS rast
), bands AS (
    SELECT ST_SetValue(
        ST_SetValue(
            ST_SetValue(rast, 1, ST_Buffer('POINT(32 96)'::geometry, 22), 220),
            2, ST_Buffer('LINESTRING(18 20,110 110)'::geometry, 6,
                         'endcap=flat join=bevel'), 210
        ),
        3, ST_Buffer('LINESTRING(10 48,118 48)'::geometry, 7,
                     'endcap=flat'), 180
    ) AS rast
    FROM canvas
)
SELECT ST_AsPNG(rast) AS "original RGB",
    ST_AsPNG(ST_Band(rast, ARRAY[2, 1, 1])) AS "bands 2,1,1",
    ST_AsPNG(ST_Band(rast, 3)) AS "band 3"
FROM bands;
                    
Вивід растрових зображень
original RGB                | bands 2,1,1                | band 3
-----------------------------+----------------------------+----------------------------
 PNG image, 128 x 128 pixels | PNG image, 128 x 128 pixels | PNG image, 128 x 128 pixels
Figure
Geometry figure for visual-rt-st-band-04

Band selection from a multi-band raster.

оригінал (стовпчик rast)

dupe_band

sing_band