ArcObjects Library Reference

Create ConditionalOp Con Raster Snippet

Create a raster from a conditional if/else evaluation of two input GeoDataset's.

[C#]
/// <summary>
/// Create a raster from a conditional if/else evaluation of two input GeoDataset's.
/// </summary>
/// <param name="geoDataset_conditional">An IGeoDataset interface that has cell values of true = 1 or false = 0.</param>
/// <param name="geoDataset_true">An IGeoDataset interface that has cell values that will be used for the output if the geoDataset_conditional is true.</param>
/// <returns>An IGeoDataset interface that is the result of the conditional if/else evaluation of the two input rasters.</returns>
/// <remarks>
/// Note: the input geoDataset's must be of Type IRaster, IRasterDataset, IRasterBand, or IRasterDescriptor.
/// 
/// The IConditionalOp.Con Method has one option (falseRAster) that 
/// will greatly vary the output raster. These values will need to be adjusted for your application to achieve 
/// the desired results.
/// 
/// For information about the IConditionalOp.Con Method see:
/// http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriSpatialAnalyst/IConditionalOp_Con.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 CreateConditionalOpConRaster(ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset_conditional, ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset_true)
{

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

        // Create the RasterConditionalOp object		
        ESRI.ArcGIS.SpatialAnalyst.IConditionalOp conditionalOp = new ESRI.ArcGIS.SpatialAnalyst.RasterConditionalOpClass();

        // Declare the output raster object			
        //Note: Adjust the IConditionalOp.Con method options to suit your applications need.
        System.Object missing = System.Type.Missing;
        ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset_output = conditionalOp.Con(geoDataset_conditional, geoDataset_true, ref missing);

        return geoDataset_output;

    }
    else
    {

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

    }

}
[Visual Basic .NET]
''' <summary>
''' Create a raster from a conditional if/else evaluation of two input GeoDataset's.
''' </summary>
''' <param name="geoDataset_conditional">An IGeoDataset interface that has cell values of true = 1 or false = 0.</param>
''' <param name="geoDataset_true">An IGeoDataset interface that has cell values that will be used for the output if the geoDataset_conditional is true.</param>
''' <returns>An IGeoDataset interface that is the result of the conditional if/else evaluation of the two input rasters.</returns>
''' <remarks>
''' Note: the input geoDataset's must be of Type IRaster, IRasterDataset, IRasterBand, or IRasterDescriptor.
''' 
''' The IConditionalOp.Con Method has one option (falseRAster) that 
''' will greatly vary the output raster. These values will need to be adjusted for your application to achieve 
''' the desired results.
''' 
''' For information about the IConditionalOp.Con Method see:
''' http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriSpatialAnalyst/IConditionalOp_Con.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 CreateConditionalOpConRaster(ByVal geoDataset_conditional As ESRI.ArcGIS.Geodatabase.IGeoDataset, ByVal geoDataset_true As ESRI.ArcGIS.Geodatabase.IGeoDataset) As ESRI.ArcGIS.Geodatabase.IGeoDataset

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

    ' Create the RasterConditionalOp object		
    Dim conditionalOp As ESRI.ArcGIS.SpatialAnalyst.IConditionalOp = New ESRI.ArcGIS.SpatialAnalyst.RasterConditionalOpClass

    ' Declare the output raster object			
    'Note: Adjust the IConditionalOp.Con method options to suit your applications need.
    Dim geoDataset_output As ESRI.ArcGIS.Geodatabase.IGeoDataset = conditionalOp.Con(geoDataset_conditional, geoDataset_true, System.Type.Missing)

    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
  • System