p.kennedy@fugro.com.au

how to set the name of a raster band in c#?

Discussion created by p.kennedy@fugro.com.au on Dec 5, 2013
Latest reply on Dec 3, 2014 by mminin
Hi,
I have a small extension to create a raster dataset with 5 bands into a GDB.  this works no problem, but I am struggling to set the name of each band to the correct name rather than the default 'value'.

Does anyone know of a code snippet to set the name of a band?

Here is a code snippet to create the bands.  It works fine, but the names are unrealistic.


//Define the origin for the raster dataset, which is the lower left corner of the raster.
            IPoint origin = new PointClass();
            origin.PutCoords(lowerLeft.x, lowerLeft.y);
            //Define the dimension of the raster dataset.
            int width = nColumns; //This is the width of the raster dataset.
            int height = nRows; //This is the height of the raster dataset.
            double xCell = cellSize; //This is the cell size in x direction.
            double yCell = cellSize; //This is the cell size in y direction.
            int NumBand = 5; // This is the number of bands the raster dataset contains.
            //Create a raster dataset in grid format.
            rasterDataset = rasterWs.CreateRasterDataset(rasterFilename, "GRID", origin, width, height, xCell, yCell, NumBand, rstPixelType.PT_FLOAT, sr, true);

            //Get the raster band.
            IRasterBandCollection rasterBands = (IRasterBandCollection)rasterDataset;
            IRasterBand rasterBand;
            IRasterProps rasterProps;
            rasterBand = rasterBands.Item(0);
            rasterProps = (IRasterProps)rasterBand;
            //Set NoData if necessary. For a multiband image, NoData value needs to be set for each band.
            const double NoDataValue = -9999.99;
            rasterProps.NoDataValue = Convert.ToSingle(NoDataValue);
            //Create a raster from the dataset.
            IRaster raster = rasterDataset.CreateDefaultRaster();
            IRasterEdit rasterEdit = (IRasterEdit)raster;

Outcomes