ArcObjects Library Reference

Create LocalOp Combine Raster Snippet

Create a raster from two combined input GeoDataset's.

[C#]
/// <summary>
/// Create a raster from two combined input GeoDataset's.
/// </summary>
/// <param name="geoDataset_1">An IGeoDataset interface that has cell values that will be combined into a new raster.</param>
/// <param name="geoDataset_2">An IGeoDataset interface that has cell values that will be combined into a new raster.</param>
/// <returns>An IGeoDataset interface that is the result of two combined GeoDatasets.</returns>
/// <remarks>
/// Note: the input geoDataset's must be of Type IRaster, IRasterDataset, IRasterBand, or IRasterDescriptor.
/// 
/// For information about the ILocalOp.Combine Method see:
/// http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriSpatialAnalyst/ILocalOp_Combine.htm
/// 
/// For more information on working with the ArcGIS Spatial Anaylst objects see:
/// http://edndoc.esri.com/arcobjects/9.2/CPP_VB6_VBA_VCPP_Doc/COM/VB6/working/work_rasters/sptl_analyst_objs.htm
/// </remarks>
public ESRI.ArcGIS.Geodatabase.IGeoDataset CreateLocalOpCombineRaster(ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset_1, ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset_2)
{

    if ((geoDataset_1 is ESRI.ArcGIS.Geodatabase.IRaster | geoDataset_1 is ESRI.ArcGIS.Geodatabase.IRasterDataset | geoDataset_1 is ESRI.ArcGIS.DataSourcesRaster.IRasterBand | geoDataset_1 is ESRI.ArcGIS.GeoAnalyst.IRasterDescriptor) & (geoDataset_2 is ESRI.ArcGIS.Geodatabase.IRaster | geoDataset_2 is ESRI.ArcGIS.Geodatabase.IRasterDataset | geoDataset_2 is ESRI.ArcGIS.DataSourcesRaster.IRasterBand | geoDataset_2 is ESRI.ArcGIS.GeoAnalyst.IRasterDescriptor))
    {

        // Declare the first input RasterBand object			
        ESRI.ArcGIS.DataSourcesRaster.IRasterBand rasterBand_1 = (ESRI.ArcGIS.DataSourcesRaster.IRasterBand)geoDataset_1; // Explicit Cast

        // Declare the second input RasterBand object			
        ESRI.ArcGIS.DataSourcesRaster.IRasterBand rasterBand_2 = (ESRI.ArcGIS.DataSourcesRaster.IRasterBand)geoDataset_2; // Explicit Cast

        // Create a RasterBandCollection			
        ESRI.ArcGIS.DataSourcesRaster.IRasterBandCollection rasterBandCollection = new ESRI.ArcGIS.DataSourcesRaster.RasterClass();
        rasterBandCollection.AppendBand(rasterBand_1);
        rasterBandCollection.AppendBand(rasterBand_2);

        ESRI.ArcGIS.Geodatabase.IGeoDataset pInputDataset = (ESRI.ArcGIS.Geodatabase.IGeoDataset)rasterBandCollection; // Explicit Cast

        // Create the RasterLocalOp object			
        ESRI.ArcGIS.SpatialAnalyst.ILocalOp localOp = new ESRI.ArcGIS.SpatialAnalyst.RasterLocalOpClass();

        // Declare the output raster object			
        ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset_output = localOp.Combine(pInputDataset);

        return geoDataset_output;

    }
    else
    {

        //Invalid type of GeoDataset for this process
        return null;

    }

}
[Visual Basic .NET]
''' <summary>
''' Create a raster from two combined input GeoDataset's.
''' </summary>
''' <param name="geoDataset_1">An IGeoDataset interface that has cell values that will be combined into a new raster.</param>
''' <param name="geoDataset_2">An IGeoDataset interface that has cell values that will be combined into a new raster.</param>
''' <returns>An IGeoDataset interface that is the result of two combined GeoDatasets.</returns>
''' <remarks>
''' Note: the input geoDataset's must be of Type IRaster, IRasterDataset, IRasterBand, or IRasterDescriptor.
''' 
''' For information about the ILocalOp.Combine Method see:
''' http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriSpatialAnalyst/ILocalOp_Combine.htm
''' 
''' For more information on working with the ArcGIS Spatial Anaylst objects see:
''' http://edndoc.esri.com/arcobjects/9.2/CPP_VB6_VBA_VCPP_Doc/COM/VB6/working/work_rasters/sptl_analyst_objs.htm
''' </remarks>
Public Function CreateLocalOpCombineRaster(ByVal geoDataset_1 As ESRI.ArcGIS.Geodatabase.IGeoDataset, ByVal geoDataset_2 As ESRI.ArcGIS.Geodatabase.IGeoDataset) As ESRI.ArcGIS.Geodatabase.IGeoDataset

  If (TypeOf geoDataset_1 Is ESRI.ArcGIS.Geodatabase.IRaster _
  Or TypeOf geoDataset_1 Is ESRI.ArcGIS.Geodatabase.IRasterDataset _
  Or TypeOf geoDataset_1 Is ESRI.ArcGIS.DataSourcesRaster.IRasterBand _
  Or TypeOf geoDataset_1 Is ESRI.ArcGIS.GeoAnalyst.IRasterDescriptor) _
  And (TypeOf geoDataset_2 Is ESRI.ArcGIS.Geodatabase.IRaster _
  Or TypeOf geoDataset_2 Is ESRI.ArcGIS.Geodatabase.IRasterDataset _
  Or TypeOf geoDataset_2 Is ESRI.ArcGIS.DataSourcesRaster.IRasterBand _
  Or TypeOf geoDataset_2 Is ESRI.ArcGIS.GeoAnalyst.IRasterDescriptor) Then

    ' Declare the first input RasterBand object			
    Dim rasterBand_1 As ESRI.ArcGIS.DataSourcesRaster.IRasterBand = CType(geoDataset_1, ESRI.ArcGIS.DataSourcesRaster.IRasterBand) ' Explicit Cast

    ' Declare the second input RasterBand object			
    Dim rasterBand_2 As ESRI.ArcGIS.DataSourcesRaster.IRasterBand = CType(geoDataset_2, ESRI.ArcGIS.DataSourcesRaster.IRasterBand) ' Explicit Cast

    ' Create a RasterBandCollection			
    Dim rasterBandCollection As ESRI.ArcGIS.DataSourcesRaster.IRasterBandCollection = New ESRI.ArcGIS.DataSourcesRaster.RasterClass
    rasterBandCollection.AppendBand(rasterBand_1)
    rasterBandCollection.AppendBand(rasterBand_2)

    Dim pInputDataset As ESRI.ArcGIS.Geodatabase.IGeoDataset = CType(rasterBandCollection, ESRI.ArcGIS.Geodatabase.IGeoDataset) ' Explicit Cast

    ' Create the RasterLocalOp object			
    Dim localOp As ESRI.ArcGIS.SpatialAnalyst.ILocalOp = New ESRI.ArcGIS.SpatialAnalyst.RasterLocalOpClass

    ' Declare the output raster object			
    Dim geoDataset_output As ESRI.ArcGIS.Geodatabase.IGeoDataset = localOp.Combine(pInputDataset)

    Return geoDataset_output

  Else

    'Invalid type of GeoDataset for this process
    Return Nothing

  End If

End Function


Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.DataSourcesRaster
  • ESRI.ArcGIS.GeoAnalyst
  • ESRI.ArcGIS.Geodatabase
  • ESRI.ArcGIS.SpatialAnalyst
  • ESRI.ArcGIS.System