4

I can successfully create this featureclass in the ArcGIS 10 default geodatabase and add it to the project, but it can't be edited. I have tried to add a feature using FeatureClass.CreateFeatureBuffer() but get the old cryptic: {"Error HRESULT E_FAIL has been returned from a call to a COM component."}

If I try to add a feature with the editing toolbar in ArcMap:

The create feature task could not be completed.

The featureclass DOES have a spatial reference that matches the data frame and the other layers in the project.
Am I missing something here? Should be easy, any ideas?

private IFeatureClass MakePointFC(IFeatureLayer pLineLayer)
{
    try
    {
        IGxCatalogDefaultDatabase Defaultgdb = ArcMap.Application as IGxCatalogDefaultDatabase;
        Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
        IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
        IWorkspace pWorkspace = workspaceFactory.OpenFromFile(Defaultgdb.DefaultDatabaseName.PathName, 0);



        IFeatureWorkspace workspace = pWorkspace as IFeatureWorkspace;
        UID CLSID = new UID();
        CLSID.Value = "esriGeoDatabase.Object";

        IFields pFields = new FieldsClass();
        IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
        pFieldsEdit.FieldCount_2 = 2;


        IGeoDataset geoDataset = pLineLayer as IGeoDataset;


        IGeometryDef pGeomDef = new GeometryDef();
        IGeometryDefEdit pGeomDefEdit = pGeomDef as IGeometryDefEdit;
        pGeomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
        pGeomDefEdit.SpatialReference_2 = geoDataset.SpatialReference;



        IField pField;
        IFieldEdit pFieldEdit;

        //pField = new FieldClass();
        //pFieldEdit = pField as IFieldEdit;
        //pFieldEdit.AliasName_2 = "ObjectID";
        //pFieldEdit.Name_2 = "ObjectID";
        //pFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
        //pFieldsEdit.set_Field(0, pFieldEdit);

        pField = new FieldClass();
        pFieldEdit = pField as IFieldEdit;
        pFieldEdit.AliasName_2 = "SHAPE";
        pFieldEdit.Name_2 = "SHAPE";
        pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
        pFieldEdit.GeometryDef_2 = pGeomDef;
        pFieldsEdit.set_Field(0, pFieldEdit);

        pField = new FieldClass();
        pFieldEdit = pField as IFieldEdit;
        pFieldEdit.AliasName_2 = "Distance";
        pFieldEdit.Name_2 = "Distance";
        pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble ;
        pFieldsEdit.set_Field(1, pFieldEdit);


        string strFCName = System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetRandomFileName());

        IFeatureClass pFeatureClass = workspace.CreateFeatureClass(strFCName, pFieldsEdit, CLSID, null, esriFeatureType.esriFTSimple, "SHAPE", "");
        return pFeatureClass;


    }
    catch (Exception ex)
    {
        return null;
    }

}
5
  • By they way, if I export the featureclass to a new featureclass, I can then edit with no problems.
    – ericoneal
    Feb 28, 2012 at 14:27
  • 1
    Did you try casting IGxCatalogDefaultDatabase.DefaultDatabaseName to IName and calling IName.Open to open the workspace instead of using the factory? Feb 28, 2012 at 14:50
  • Also, did you try with a friendly name instead of that returned by GetRandomFileName? Why is the OID field code commented out? I prefer using IFieldsEdit.AddField instead of setfield. Feb 28, 2012 at 14:53
  • Thanks Kirk, the problem was with the UID value. Seems that it should be "esriGeodatabase.Feature", not "esriGeoDatabase.Object". Your suggestion for using IName directed me to a post from a familiar author on ESRI's old forum (forums.esri.com/Thread.asp?c=93&f=1170&t=217820) regarding making an InMemoryWorspace (which will also work for my purposes). Will credit you if you want to post the answer. Additionally, I was using a random filename to avoid overwrite errors in the geodatabase, which seems to work fine and the OID field will be genereated automatically.
    – ericoneal
    Feb 28, 2012 at 16:10
  • 2
    Eric: if Kirk doesn't add more please feel free to answer your own question and select it as the most correct answer. This site is all about good answers, it doesn't matter where they come from. ;-) It's okay to elaborate on someone else's key idea. Feb 29, 2012 at 21:31

1 Answer 1

3

In the code above, "esriGeodatabase.Object" should be: "esriGeodatabase.Feature".

1
  • 3
    +1 I certainly wouldn't Object if you checked this answer as the correct answer. Mar 1, 2012 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.