//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());
}
//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);