Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

All,

I have a featureclass with Arcobjects that came from a Shape file and I wish to import it into a geodatabase. I have the geodatabase connection, I just don't know how to load the feature class to a Geodatabase. Any help would be amazing!

Im looking for a code example seeing I can't find it by googling. Hopefully in C#, but I don't mind reading through VB if needed.

Thanks.

EDIT:

I wanted to add the Answer thanks to George so here is a code snippet with comments.

 ESRI.ArcGIS.Geodatabase.IWorkspace pWorkspace;
        ESRI.ArcGIS.Geodatabase.IWorkspaceFactory pWorkspaceFactory;
        ESRI.ArcGIS.Geodatabase.IFeatureWorkspace SdeFeatureWorkspace;

        pWorkspaceFactory = new FileGDBWorkspaceFactory();
        pWorkspace = pWorkspaceFactory.OpenFromFile(@"C:\tests\test.gdb", 0); //Opens the Geodeabase and creates a connection.
        SdeFeatureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)pWorkspace;

        IWorkspaceFactory workspaceFactoryShape = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass(); //creates a shape factory to pull the shape and create the feature class.
        IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspaceFactoryShape.OpenFromFile(@"C:\Users\Desktop\Newfolder", 0); //Opens the Shape file.
        IFeatureClass featureClass = featureWorkspace.OpenFeatureClass("al012009.001_5day_lin"); //opens the featurclass from the shapefile

        SdeFeatureWorkspace.CreateFeatureClass("al012009001_5day_linnn", featureClass.Fields, featureClass.CLSID, featureClass.EXTCLSID, featureClass.FeatureType, featureClass.ShapeFieldName, null); //creates a feature class in the geodb.

        Geoprocessor gp = new Geoprocessor(); //starts a GEOprocess.
        gp.SetEnvironmentValue("workspace", @"C:\Tests\test.gdb"); //sets the geodb to use

        ESRI.ArcGIS.DataManagementTools.Append  append = new ESRI.ArcGIS.DataManagementTools.Append(); //this tool uploads the feature class
        append.inputs = featureClass;
        append.target = @"C:\tests\test.gdb\al012009001_5day_linnn";

        gp.Execute(append, null); 
share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

Given the details, you can construct a new feature class based on the details of your in memory object (IFields, etc)

You can view examples in the .NET ArcObjects documentation (ms-help://ESRI.EDNv9.3/esriGeoDatabase/html/IFeatureWorkspace.CreateFeatureClass_Example.htm)

After creating it, you can insert each object. This is a painful/ineffective way, but it should work.

Another option that you have is to use the IGeoprocessor interface and IGPProcess, and execute a tool like append.

ms-help://ESRI.EDNv9.3/ArcGIS.DataManagementTools/ESRI.ArcGIS.DataManagementTools.AppendMembers.html

share|improve this answer
    
Your Awesome George.. Thanks! –  SpoiledTechie.com Aug 2 '10 at 20:33
1  
No problem. You should check waterboys response. It's also a manner to insert a featureclass inside a geodatabase. –  George Aug 3 '10 at 2:15
add comment

I think this could be accomplished more simply by using the Copy method of the IDataset interface.

Once you have the existing feature class(featureClass in your example) and destination workspace defined (pWorkspace in your example)

Use the following where "CopyName" can be changed to whatever you want the new feature class to be named ("al012009001_5day_linnn" for your example)

ESRI.ArcGIS.Geodatabase.IDataset dataset = featureClass;
dataset.Copy("CopyName", pWorkspace);
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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