Select to view content in your preferred language

Transfering data into ArcSDE

782
1
08-27-2010 04:37 AM
MattMoyles
Occasional Contributor
I'm still a bit new to ArcObjects and was having some trouble figuring  out how to write to my SDE database.  What I basically am doing is  taking a KML file reading it into a GDB folder on my local machine and  then trying to take that data and pass it along to the SDE database.   There may be some intermediate processing between grabbing the data and  putting into the SDE database in the future but for now I'm just trying  to copy over.  So everything is working great except I can't figure out  how to transfer my data from my FeatureWorkspace into my SDE Workspace.

My code is below if anyone could give me a hand I would very much appreciate it!

//open the database created by the KMLToLayer tool in a workspace
                IWorkspaceFactory2 kmlWorkspaceFactory = new FileGDBWorkspaceFactoryClass();
                IFeatureWorkspace kmlWorkspace =  (IFeatureWorkspace)kmlWorkspaceFactory.OpenFromFile(path +  "\\NWS_Warnings.gdb", 0);

                IQueryFilter qry = new QueryFilterClass();
                qry.WhereClause = "OID > 0";

                IFeatureClass ifc = kmlWorkspace.OpenFeatureClass("Placemarks_line");
                Console.WriteLine("[Message]: Selected featureclass Placemarks_line.");

                /*IFeatureCursor features = ifc.Search(qry, false);
                int nameFieldIndex = features.FindField("OID");
                IFeature cur;     
          
                while ((cur = features.NextFeature()) != null)
                {
                    Console.WriteLine("OBJECTID = " + cur.get_Value(nameFieldIndex));
                }*/

                try
                {
                    //initialize sde connection
                    IGeoDataServer sdeServer =  InitGeoDataServerFromConnectionString("SERVER=192.168.1.107;INSTANCE=5151;VERSION=SDE.DEFAULT;USER=sde;PASSWORD=Try_n0w!;DATABASE=SDESQL");
                    IGeoDataServerObjects gsobj = sdeServer as IGeoDataServerObjects;
                    IWorkspace pWorkspace = gsobj.DefaultWorkingWorkspace;

                    ITable table = ifc as Table;

                    //Start Editing
                    IWorkspaceEdit wspEdit = pWorkspace as IWorkspaceEdit;
                    wspEdit.StartEditing(false);
                    wspEdit.StartEditOperation();

                    //sdeServer.
                    
                }
                catch (Exception e)
                {
                    Console.WriteLine("[Error]: Could not establish a connection to the ArcSDE server.");
                    Console.WriteLine(e.ToString());
                }
It's kind of a work in progress since I'm a bit stumped right now.  I'm not actually getting any errors.
0 Kudos
1 Reply
MattMoyles
Occasional Contributor
well figured it out for anyone else interested here is how I did it.  I am transferring data from a personal file GDB and dumping it onto our ArcSDE server.  Here is the code (it's a little raw, just got it working):

                //create workspace name objects
                IWorkspaceName sourceWorkspaceName = new WorkspaceNameClass();
                IWorkspaceName targetWorkspaceName = new WorkspaceNameClass();
                IName targetName = (IName)targetWorkspaceName;

                //set the source workspace name properties
                sourceWorkspaceName.PathName = path + "\\NWS_Warnings.gdb";
                sourceWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesGDB.FileGDBWorkspaceFactory";

                try
                {
                    //set the target workspace and properties
                    IPropertySet connectionProperties = new PropertySetClass();
                    connectionProperties.SetProperty("server", "*****");
                    connectionProperties.SetProperty("instance", "5151");
                    connectionProperties.SetProperty("database", "SDESQL");
                    connectionProperties.SetProperty("user", "sde");
                    connectionProperties.SetProperty("password", "*****");
                    connectionProperties.SetProperty("version", "SDE.DEFAULT");
                    targetWorkspaceName.ConnectionProperties = connectionProperties;
                    targetWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesGDB.SdeWorkspaceFactory";                
                }
                catch (Exception e)
                {
                    Console.WriteLine("[Error]: Could not establish a connection to the ArcSDE server.");
                    Console.WriteLine(e.ToString());
                    return;
                }

                //create a name object for the source feature class
                IFeatureClassName featureClassName = new FeatureClassNameClass();

                //set the featureClassName properties
                IDatasetName sourceDatasetName = (IDatasetName)featureClassName;
                sourceDatasetName.WorkspaceName = sourceWorkspaceName;
                sourceDatasetName.Name = "Placemarks_line";
                IName sourceName = (IName)sourceDatasetName;

                //create an enumerator for source datasets
                IEnumName sourceEnumName = new NamesEnumeratorClass();
                IEnumNameEdit sourceEnumNameEdit = (IEnumNameEdit)sourceEnumName;

                //add the name object for the source class to the enumerator
                sourceEnumNameEdit.Add(sourceName);

                //create a GeoDBDataTransfer object and a null name mapping enumerator
                IGeoDBDataTransfer geoDBDataTransfer = new GeoDBDataTransferClass();
                IEnumNameMapping enumNameMapping = null;

                //use the data transfer object to create a name mapping enumerator
                Boolean conflictsFound = geoDBDataTransfer.GenerateNameMapping(sourceEnumName, targetName, out enumNameMapping);
                enumNameMapping.Reset();

                // Start the transfer.
                geoDBDataTransfer.Transfer(enumNameMapping, targetName);
0 Kudos