名稱

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=,);

描述

傳回現有網格的一個或多個波段,作為新的網格。適用於從現有網格建立新的網格,或是僅匯出網格的選定波段,或是重新排列網格中波段的順序。如果未指定波段,或指定的任何波段不存在於網格中,則會傳回所有波段。在各種函式中用作輔助函式,例如用於刪除波段。

[Warning]

對於函式的 nbands 作為文字變體,預設分隔符為 ,,這表示您可以要求 '1,2,3',如果您想要使用不同的分隔符,您可以使用 ST_Band(rast, '1@2@3', '@')。對於要求多個波段,我們強烈建議您使用此函式的陣列形式,例如 ST_Band(rast, '{1,2,3}'::int[]);,因為 text 波段列表形式可能會在 PostGIS 的未來版本中移除。

可用性:2.0.0

範例

-- Make 2 new rasters: 1 containing band 1 of dummy, second containing band 2 of dummy and then reclassified as a 2BUI
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
SELECT ST_NumBands(ST_Band(rast, '{2,3}'::int[])) As num_bands
    FROM dummy_rast WHERE rid=2;

num_bands
----------
2

-- Return bands 2 and 3. Use array to define bands
SELECT ST_NumBands(ST_Band(rast, ARRAY[2,3])) As num_bands
    FROM dummy_rast
WHERE rid=2;
                    

原始 (欄位 rast)

重複波段

單一波段

--Make a new raster with 2nd band of original and 1st band repeated twice,
and another with just the third band
SELECT rast, ST_Band(rast, ARRAY[2,1,1]) As dupe_band,
    ST_Band(rast, 3) As sing_band
FROM samples.than_chunked
WHERE rid=35;