AnsweredAssumed Answered

Add a Raster field to a feature class [ArcObjects 10]

Question asked by AkhilP on Jul 26, 2012
Latest reply on Jul 27, 2012 by AkhilP
I am trying to create a feature class using C# and ArcObjects and it needs to have a raster field. However I am getting an error when I try to create the feature class.

Here is a snippet of the code I am using.

public IFields CreateFields(ISpatialReference spatialReference)         {             IFields fields = new FieldsClass();             IFieldsEdit fieldsEdit = (IFieldsEdit)fields;             fieldsEdit.FieldCount_2 = 3;                          //Create the Object ID field.             IField fieldUserDefined = new Field();             IFieldEdit fieldEdit = (IFieldEdit)fieldUserDefined;             fieldEdit.Name_2 = "OBJECTID";             fieldEdit.AliasName_2 = "OBJECT ID";             fieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;             fieldsEdit.set_Field(0, fieldUserDefined);              // Create the Shape field.             fieldUserDefined = new Field();             fieldEdit = (IFieldEdit)fieldUserDefined;             // Set up the geometry definition for the Shape field.             IGeometryDef geometryDef = new GeometryDefClass();             IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;             geometryDefEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint;             // By setting the grid size to 0, you're allowing ArcGIS to determine the appropriate grid sizes for the feature class.              // If in a personal geodatabase, the grid size will be 1000. If in a file or ArcSDE geodatabase, the grid size             // will be based on the initial loading or inserting of features.             geometryDefEdit.GridCount_2 = 1;             geometryDefEdit.set_GridSize(0, 0);             geometryDefEdit.HasM_2 = false;             geometryDefEdit.HasZ_2 = false;             //Assign the spatial reference that was passed in, possibly from             //IGeodatabase.SpatialReference for the containing feature dataset.             if (spatialReference != null)             {                 geometryDefEdit.SpatialReference_2 = spatialReference;             }              // Set standard field properties.             fieldEdit.Name_2 = "SHAPE";             fieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;             fieldEdit.GeometryDef_2 = geometryDef;             fieldEdit.IsNullable_2 = true;             fieldEdit.Required_2 = true;             fieldsEdit.set_Field(1, fieldUserDefined);              fieldUserDefined = new Field();             fieldEdit = (IFieldEdit)fieldUserDefined;             fieldEdit.Name_2 = "PHOTO";             fieldEdit.AliasName_2 = "Attach a Photo";             fieldEdit.Editable_2 = true;             fieldEdit.IsNullable_2 = false;             fieldEdit.Type_2 = esriFieldType.esriFieldTypeRaster;             fieldsEdit.set_Field(2, fieldUserDefined);


After the fields have been defined, the following method is called to create the feature class.

public IFeatureClass CreateFeatureDatasetFeatureClass(IFeatureDataset featureDataset, String featureClassName, IFields fieldsCollection, String shapeFieldName)         {             IFeatureClassDescription fcDesc = new FeatureClassDescriptionClass();             IObjectClassDescription ocDesc = (IObjectClassDescription)fcDesc;              // Use IFieldChecker to create a validated fields collection.             IFieldChecker fieldChecker = new FieldCheckerClass();             IEnumFieldError enumFieldError = null;             IFields validatedFields = null;             fieldChecker.ValidateWorkspace = featureDataset.Workspace;             fieldChecker.Validate(fieldsCollection, out enumFieldError, out validatedFields);              // The enumFieldError enumerator can be inspected at this point to determine              // which fields were modified during validation.             IFeatureClass featureClass = featureDataset.CreateFeatureClass(featureClassName,                 validatedFields, ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID,                 esriFeatureType.esriFTSimple, fcDesc.ShapeFieldName, "");             return featureClass;         }


On the last line of code I  get an error: Value does not fall within the expected range.
If I change the code to create the field,
from :
fieldEdit.Type_2 = esriFieldType.esriFieldTypeRaster;
to:
fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;

It works. But I obviously don't want a string field, I would like to have a raster field.

Can someone please help me out, that would be greatly appreciated.

Thanks!

Outcomes