Nom

ST_AddBand — Retourne un raster avec la/les nouvelle(s) bande(s) ajouté(s) à un index donné, de type et valeur initiale donnés. Si aucun index n'est spécifié, la bande est ajoutée à la fin.

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

Description

Renvoie un raster avec une nouvelle bande ajoutée à la position donnée (index), du type donné, de la valeur initiale donnée et de la valeur de nodata donnée. Si aucun index n'est spécifié, la bande est ajoutée à la fin. Si aucun fromband n'est spécifié, la bande 1 est supposée. Le type de pixel est une représentation sous forme de chaîne de l'un des types de pixels spécifiés dans ST_BandPixelType. Si un index existant est spécifié, toutes les bandes suivantes >= cet index sont incrémentées de 1. Si une valeur initiale supérieure à la valeur maximale du type de pixel est spécifiée, la valeur initiale est fixée à la valeur la plus élevée autorisée par le type de pixel.

Pour la variante acceptant un tableau de addbandarg en paramètre (Variante 1), un index spécifique au paramètre addbandarg est relative au raster au moment où la bande décrite par ce paramètre addbandarg est ajoutée au raster. Voir l'exemple Multiples nouvelles bandes ci-dessous.

Pour la variante acceptant un tableau de rasters (Variante 5), si torast est NULL, alors la bande fromband de chaque raster est accumulée dans le nouveau raster.

Pour les variantes acceptant un paramètre outdbfile (Variantes 6 et 7), la valeur doit correspondre au chemin complet vers le fichier raster. Ce fichier doit être accessible par le processus du serveur postgres.

Amélioration : 2.1.0 ajout du paramètre addbandarg.

Amélioration : 2.1.0 introduction du support des bandes out-db.

Exemples

Single New Band.

This example adds another 8-bit unsigned integer band with pixels initialized to 200.

Code
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.

Code
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;
Export de raster
pixeltype | nodatavalue | isoutdb | path
-----------+----------------+-------------+---------+------
 1BB       |             | f       |
 4BUI      |             | f       |

This example outputs metadata for the raster.

Code
SELECT  (rmd).width, (rmd).height, (rmd).numbands
FROM (SELECT ST_MetaData(rast) As rmd
    FROM dummy_rast WHERE rid = 10) AS foo;
Export de raster
width | height | numbands
-------+--------+----------
   100 |    100 |        2

Multiple New Bands.

Code
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[]
);
Export de raster
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.

Code
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.

Code
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[]
);
Export de raster
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