Select to view content in your preferred language

Personal GDB FeatureClass.CreateFeature() "Item not found in this collection." error

3241
10
03-04-2011 09:48 AM
ErikLee
Emerging Contributor
I create a personal geodatabase and then a FeatureClass in that gdb to store the results of an analysis. When I call <FeatureClass>.CreateFeature() I get an exception message "Item not found in this collection." I've ensured my fields are set correctly, I physically open the .mdb and the table looks correct. Here's my code (I'm using properties from an existing SDE featureclass (pipeFittingFeatureClass) to construct the new FeatureClass):

                //create the 'ServicePointCount' field
                IFieldEdit servicePointCountFieldEdit = new FieldClass();
                servicePointCountFieldEdit.Name_2 = "ServicePointCount";
                servicePointCountFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;

                //create ORIG_OID field
                IFieldEdit origOIDFieldEdit = new FieldClass();
                origOIDFieldEdit.Name_2 = "ORIG_OID";
                origOIDFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;

                //create OID field
                IFieldEdit OIDFieldEdit = new FieldClass();
                OIDFieldEdit.Name_2 = "ObjectID";
                OIDFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;

                //create shape field
                IFieldEdit shapeFieldEdit = new FieldClass();
                shapeFieldEdit.Name_2 = this.pipeFittingFeatureClass.ShapeFieldName;
                shapeFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                IGeometryDef shapeFieldGeometryDefinition = new GeometryDefClass();
                IGeometryDefEdit shapeFieldGeometryDefinitionEdit = (IGeometryDefEdit)shapeFieldGeometryDefinition;
                shapeFieldGeometryDefinitionEdit.GeometryType_2 = this.pipeFittingFeatureClass.ShapeType;
                ISpatialReferenceFactory3 spatialRefFactory = new SpatialReferenceEnvironmentClass();
                ISpatialReference origRef = this.pipeFittingFeatureClass.Fields.get_Field(this.pipeFittingFeatureClass.Fields.FindField("SHAPE")).GeometryDef.SpatialReference;
                shapeFieldGeometryDefinitionEdit.SpatialReference_2 = spatialRefFactory.ConstructHighPrecisionSpatialReference(origRef, -1, 0, 0);
                shapeFieldEdit.GeometryDef_2 = shapeFieldGeometryDefinitionEdit;

                //create new fields class
                IFieldsEdit fieldsEdit = new FieldsClass();
                fieldsEdit.FieldCount_2 = 4;//this.pipeFittingFeatureClass.Fields.FieldCount + 2;
                fieldsEdit.set_Field(0, (IField)OIDFieldEdit);
                fieldsEdit.set_Field(1, (IField)origOIDFieldEdit);
                fieldsEdit.set_Field(2, (IField)servicePointCountFieldEdit);
                fieldsEdit.set_Field(3, (IField)shapeFieldEdit);

                //create the featureclass
                IFeatureClass EFVValvesFeatureClass = workspace.CreateFeatureClass("EFVValves", (IFields)fieldsEdit, null,
                    null, this.pipeFittingFeatureClass.FeatureType, this.pipeFittingFeatureClass.ShapeFieldName, "");

                //THIS THROWS THE "Item not found in this collection." EXCEPTION
                IFeature newFeature = EFVValvesFeatureClass.CreateFeature();


I tried searching for this error and got a few hits but none of the fixes applied to my situation so I am at a loss as to ideas. My suspicion is the how I define the Shape field, but if I do not create a high precision spatial reference (the template spatial reference I use is low), it won't even allow me to create the featureclass.

For reference, I'm using ArcGIS 9.3.1 Sp1, and this is just a small console app that does some custom tracing and stores the results in this personal GDB.
0 Kudos
10 Replies
M_DJohnson
Regular Contributor
Hi,

I also getting same error while create a new features in geometric network featureclass. The below code is fine on normal featureclass. The error is throwing at geometry set. Can you please guide me what is the best approach to create network feature and can suggest any sample.
database : ArcFM 9.2 pgdb.

Regards
Johnson

IFeatureLayer pFeatureLayer = pMap.get_Layer(0) as IFeatureLayer;

            //get a reference to the editor
            UID uid = new UIDClass();
            uid.Value = "esriEditor.Editor";

            IEditor m_editor = m_application.FindExtensionByCLSID(uid) as ESRI.ArcGIS.Editor.IEditor;

            if (m_editor.EditState == esriEditState.esriStateNotEditing)
            {
                m_editor.StartEditing(pFeatureLayer.FeatureClass.FeatureDataset.Workspace);
            }

            m_editor.StartOperation();

            IPoint pPoint = new PointClass();
            pPoint.X = 1302764.772;
            pPoint.Y = 11998729.284;           

            IFeature pFeature = pFeatureLayer.FeatureClass.CreateFeature();

            try
            {
                pFeature.Shape = pPoint;
                pFeature.set_Value(pFeature.Fields.FindField("CreationUser"), "XYZ");
                pFeature.set_Value(pFeature.Fields.FindField("Owner"), "CUS");

                pFeature.Store();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            if (m_editor.EditState != esriEditState.esriStateNotEditing)
            {
                m_editor.StopOperation("New Transformer");
                m_editor.StopEditing(true);
            }
0 Kudos