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


How to load a raster dataset to the raster field in a feature class (ArcObjects .NET 10.6 SDK)
ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Managing data > Working with image and raster data > Working with raster catalogs > How to load a raster dataset to the raster field in a feature class (ArcObjects .NET 10.6 SDK)

How to load a raster dataset to the raster field in a feature class


Summary
A feature class or table can have a raster attribute field to store any raster related to the feature. You can edit raster values in the raster field using the Editor tool. If you have many raster datasets to add to the raster field, you need to write a custom application to simplify the workflow.

Loading a raster dataset to the raster field in a feature class

To load a raster dataset to the raster field, follow these steps:
  1. Get a workspace for editing.
  2. Find the raster field index.
  3. Create a raster value object with an input raster dataset.
  4. Set the raster value to the raster field.
  5. Stop editing and save.
The following code sample shows how to load a raster dataset into a feature in a feature class given the ObjectID (OID) of the feature. Only geodatabase feature classes can have a raster attribute field.
[C#]
static void LoadToRasterAttribute(IFeatureClass featureClass, IRasterDataset
    rasterDataset, int OID)
{
    /*Parameters:
    featureClass—The feature class with raster attribute.
    rasterDataset—The raster dataset to be loaded to the raster attribute.
    OID—The ObjectID of the feature to be edited.
     */

    //Get workspace for editing.
    IDataset dataset=(IDataset)featureClass;
    IWorkspaceEdit workspaceEdit=(IWorkspaceEdit)dataset.Workspace;
    workspaceEdit.StartEditing(false);
    workspaceEdit.StartEditOperation();
    IFeature feature=featureClass.GetFeature(OID);

    //Find raster field index.
    int iRasterField=0;
    for (int i=0; i < feature.Fields.FieldCount; i++)
    {
        if (feature.Fields.get_Field(i).Type == esriFieldType.esriFieldTypeRaster)
        {
            iRasterField=i;
            i=1000;
        }
    }

    //Create raster value with input raster dataset.
    IRasterValue rasterValue=new RasterValueClass();
    rasterValue.RasterDataset=rasterDataset;

    //Set raster value to the raster field.
    feature.set_Value(iRasterField, rasterValue);
    feature.Store();

    //Stop editing and save edits.
    workspaceEdit.StopEditOperation();
    workspaceEdit.StopEditing(true);
}
[VB.NET]
Public Sub LoadToRasterAttribute(ByVal featureClass As IFeatureClass, ByVal rasterDataset As IRasterDataset, ByVal OID As Integer) ' Parameters:
    ' featureClass—The feature class with raster attribute.
    ' rasterDataset—The raster dataset to be loaded to the raster attribute.
    ' OID—The ObjectID of the feature to be edited.
    
    'Get workspace for editing.
    Dim dataset As IDataset=CType(featureClass, IDataset)
    Dim workspaceEdit As IWorkspaceEdit=CType(dataset.Workspace, IWorkspaceEdit)
    workspaceEdit.StartEditing(False)
    workspaceEdit.StartEditOperation()
    
    Dim feature As IFeature=featureClass.GetFeature(OID)
    'Find raster field index.
    Dim iRasterField As Integer=0
    Dim i As Integer
    For i=0 To feature.Fields.FieldCount - 1 Step i + 1
        If feature.Fields.get_Field(i).Type=esriFieldType.esriFieldTypeRaster Then
            iRasterField=i
            i=1000
        End If
    Next
    
    'Create raster value with input raster dataset.
    Dim rasterValue As IRasterValue=New RasterValueClass()
    rasterValue.RasterDataset=rasterDataset
    
    'Set raster value to the raster field.
    feature.set_Value(iRasterField, rasterValue)
    feature.Store()
    
    'Stop editing and save edits.
    workspaceEdit.StopEditOperation()
    workspaceEdit.StopEditing(True)
End Sub






To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcGIS Desktop Basic ArcGIS Desktop Basic
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Advanced ArcGIS Desktop Advanced
Engine Developer Kit Engine