Thursday, December 3, 2009

Load Raster Data to a Field

A raster field is a column that allow a user to store raster objects in them. Rasters can be any imagery, jpg, pngs, etc...

To load data into the field you need to do the following:


///
/// Loads a raster into a raster field
///

/// feature where photo will be stored
/// image to be stored in record
/// Row of data to get the feature to store the raster dataset
/// Name of Raster field to save image to
public void LoadRasterDatasetToRasterField( IFeatureClass featureClass,
IRasterDataset rasterDataset, int OID, string RasterField )
{
try
{

//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 = feature.Fields.FindField( RasterField );

//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 );
}
catch (Exception ex)
{

MessageBox.Show( ex.Message );
}
}


This function basically starts an edit session to put data into the column. That means the featureclass be able to be edited.

Enjoy,

(I haven't forgot about Part 2 of my previous post, I've just been busy)

No comments: