Create ExtractionOp Attribute Raster Snippet (ArcObjects .NET 10.6 SDK)
ArcObjects Library Reference

Create ExtractionOp Attribute Raster Snippet

Create an raster from a logical based attribute query of an input GeoDataset.

[C#]
/// <summary>
/// Create an raster from a logical based attribute query of an input GeoDataset.
/// </summary>
/// <param name="geoDataset">An IGeoDataset interface that has cell values that will be selected based upon an attribute query.</param>
/// <param name="string_WhereClause">A System.String that is the where clause portion of the attribute query. Example: "Value=3".</param>
/// <param name="string_FieldName">A System.String that is the Field name in the input geoDataset.</param>
/// <returns>An IGeoDataset interface that contains generalization values of the input raster.</returns>
/// <remarks>
/// Note: the input geoDataset must be of Type IRaster, IRasterDataset, IRasterBand, or IRasterDescriptor.
/// 
/// For information about the IExtractionOp.Attribute Method see:
/// http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriSpatialAnalyst/IExtractionOp_Attribute.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 CreateExtractionOpAttributeRaster(ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset, System.String string_WhereClause, System.String string_FieldName)
{

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

        // Create the RasterExtractionOp object
        ESRI.ArcGIS.SpatialAnalyst.IExtractionOp extractionOp=new ESRI.ArcGIS.SpatialAnalyst.RasterExtractionOpClass();

        // Declare the input object
        ESRI.ArcGIS.Geodatabase.IRaster raster=(ESRI.ArcGIS.Geodatabase.IRaster)geoDataset;

        // Declare a RasterDescriptor
        ESRI.ArcGIS.GeoAnalyst.IRasterDescriptor rasterDescriptor=new ESRI.ArcGIS.GeoAnalyst.RasterDescriptorClass();

        // Select the field used for extraction
        ESRI.ArcGIS.Geodatabase.IQueryFilter queryFilter=new ESRI.ArcGIS.Geodatabase.QueryFilterClass();
        queryFilter.WhereClause=string_WhereClause;

        rasterDescriptor.Create(raster, queryFilter, string_FieldName);

        // Call the method
        // Note: the input rasterDescriptor that is created by a logical expression based on the attributes in a Raster. 
        // Those cells for which the logical expression evaluated to True in the RasterDescriptor are selected. 
        // Those cells that are not selected will be set to NoData.
        ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset_output=extractionOp.Attribute(rasterDescriptor);

        return geoDataset_output;

    }
    else
    {

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

    }

}
[Visual Basic .NET]
''' <summary>
''' Create an raster from a logical based attribute query of an input GeoDataset.
''' </summary>
''' <param name="geoDataset">An IGeoDataset interface that has cell values that will be selected based upon an attribute query.</param>
''' <param name="string_WhereClause">A System.String that is the where clause portion of the attribute query. Example: "Value=3".</param>
''' <param name="string_FieldName">A System.String that is the Field name in the input geoDataset.</param>
''' <returns>An IGeoDataset interface that contains generalization values of the input raster.</returns>
''' <remarks>
''' Note: the input geoDataset must be of Type IRaster, IRasterDataset, IRasterBand, or IRasterDescriptor.
''' 
''' For information about the IExtractionOp.Attribute Method see:
''' http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriSpatialAnalyst/IExtractionOp_Attribute.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 CreateExtractionOpAttributeRaster(ByVal geoDataset As ESRI.ArcGIS.Geodatabase.IGeoDataset, ByVal string_WhereClause As System.String, ByVal string_FieldName As System.String) As ESRI.ArcGIS.Geodatabase.IGeoDataset

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

    ' Create the RasterExtractionOp object
    Dim extractionOp As ESRI.ArcGIS.SpatialAnalyst.IExtractionOp=New ESRI.ArcGIS.SpatialAnalyst.RasterExtractionOpClass

    ' Declare the input object
    Dim raster As ESRI.ArcGIS.Geodatabase.IRaster=CType(geoDataset, ESRI.ArcGIS.Geodatabase.IRaster)

    ' Declare a RasterDescriptor
    Dim rasterDescriptor As ESRI.ArcGIS.GeoAnalyst.IRasterDescriptor=New ESRI.ArcGIS.GeoAnalyst.RasterDescriptorClass

    ' Select the field used for extraction
    Dim queryFilter As ESRI.ArcGIS.Geodatabase.IQueryFilter=New ESRI.ArcGIS.Geodatabase.QueryFilterClass
    queryFilter.WhereClause=string_WhereClause

    rasterDescriptor.Create(raster, queryFilter, string_FieldName)

    ' Call the method
    ' Note: the input rasterDescriptor that is created by a logical expression based on the attributes in a Raster. 
    ' Those cells for which the logical expression evaluated to True in the RasterDescriptor are selected. 
    ' Those cells that are not selected will be set to NoData.
    Dim geoDataset_output As ESRI.ArcGIS.Geodatabase.IGeoDataset=extractionOp.Attribute(rasterDescriptor)

    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