Loading a raster dataset to a raster attribute column in a feature class
A feature class or table can have a raster attribute field to store any raster related to the feature. This article 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. See the following code example:
[Java]
static void loadToRasterAttribute(IFeatureClass featureClass, IRasterDataset
rasterDataset, int OID)throws Exception{
/*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.getWorkspace();
workspaceEdit.startEditing(false);
workspaceEdit.startEditOperation();
IFeature feature = featureClass.getFeature(OID);
//Find raster field index
int iRasterField = 0;
for (int i = 0; i < feature.getFields().getFieldCount(); i++){
if (feature.getFields().getField(i).getType() ==
esriFieldType.esriFieldTypeRaster){
iRasterField = i;
i = 1000;
}
}
//Create raster value with input raster dataset
IRasterValue rasterValue = new RasterValue();
rasterValue.setRasterDatasetByRef(rasterDataset);
//Set raster value to the raster field
feature.setValue(iRasterField, rasterValue);
feature.store();
//Stop editing and save edits
workspaceEdit.stopEditOperation();
workspaceEdit.stopEditing(true);
}
Development licensing | Deployment licensing |
---|---|
ArcView | ArcView |
ArcEditor | ArcEditor |
ArcInfo | ArcInfo |
Engine Developer Kit | Engine Runtime |