This document is archived and information here might be outdated.  Recommended version.


Handling multiband output (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > ArcGIS extensions > Spatial Analyst > Handling multiband output

Handling multiband output


Summary
This topic provides a brief introduction on how to work with multiband raster output with spatial analysis operations.

About handling multiband output

Some methods, such as Curvature, EucDistanceFull, CostDistanceFull, and FlowDirection, can return optional outputs from the operation. In these cases, the output Raster object contains more than one band. Each band in the output Raster points to a different output temporary dataset. The first band is the default output of the method and the bands are placed in the same order as they appear in the method signature.
To save each band as a separate raster dataset, use the IRasterBandCollection interface on the output Raster and individually access the bands. Once you have the individual bands, you can save them as permanent datasets. You can also save the output Raster as a multiband raster dataset.
The following code example shows how to access the second band and the profile curve from the results of the Curvature method:
[C#]
public IRaster GetSecondRaster(IRaster raster_ResultOfCurvature)
{
    IRaster raster=null;
    // Gets the second band of a multiband raster.
    IRasterBandCollection rasterBandCollection=(IRasterBandCollection)
        raster_ResultOfCurvature;
    IRasterBand rasterBand=null;
    IRasterDataset rasterDataset=null;
    if (rasterBandCollection.Count > 1)
    {
        rasterBand=rasterBandCollection.Item(1);
        rasterDataset=rasterBand.RasterDataset;
        raster=rasterDataset.CreateDefaultRaster();
    }
    else
    {
        raster=null;
    }
    return raster;
}
[VB.NET]
Public Function GetSecondRaster(ByVal raster_ResultOfCurvature As IRaster) As IRaster
    Dim raster As IRaster
    ' Gets the second band of a multiband raster.
    Dim rasterBandCollection As IRasterBandCollection=CType(raster_ResultOfCurvature, IRasterBandCollection)
    Dim rasterBand As IRasterBand
    Dim rasterDataset As IRasterDataset
    If rasterBandCollection.Count > 1 Then
        rasterBand=rasterBandCollection.Item(1)
        rasterDataset=rasterBand.RasterDataset
        raster=rasterDataset.CreateDefaultRaster
    Else
        raster=Nothing
    End If
    Return raster
End Function






Development licensing Deployment licensing
ArcGIS Desktop Basic: Spatial Analyst ArcGIS Desktop Basic
ArcGIS Desktop Standard: Spatial Analyst ArcGIS Desktop Standard
ArcGIS Desktop Advanced: Spatial Analyst ArcGIS Desktop Advanced