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

2661
2
12-05-2013 07:39 PM
paulkennedy
New Contributor II
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;
0 Kudos
2 Replies
MichaelEber
Occasional Contributor
This may provide you with what you need.  In this example they are creating rasters from TIFF objects and assigning names.
0 Kudos
MikhailMinin
New Contributor

To change ESRI.ArcGIS.DataSourcesRaster.IRasterBand.Bandname property, you must cast ESRI.ArcGIS.DataSourcesRaster.IRasterBand object into ESRI.ArcGIS.Geodatabase.IDataset interface and run IDataset.Rename() method.

0 Kudos