I have a table and a layer joined fine, I am trying to export the end result into a file geodatabase, the export is fine if I specify specific name, other than that it exports the original layer data.Here is the code I am using:
public void JoinLT(string DataPath,string Sheet, int lyrIndex, string JoinName, string TableFieldName,string FCFieldName, string FCName, string TableName) //Export the lakes from the GNE_Layer, to an already defined file geodatabase { try { // Part 1: Define the Environoment IMxDocument mxDoc = (IMxDocument)ArcMap.Application.Document; IMap map = mxDoc.FocusMap; ILayer layer = map.Layer[lyrIndex]; // GNE_Clip IFeatureLayer featureLayer = (IFeatureLayer)layer; IFeatureClass featureClass = featureLayer.FeatureClass; IWorkspaceFactory WsF = new ExcelWorkspaceFactory(); //Open the Excel sheet IFeatureWorkspace fWs = (IFeatureWorkspace)WsF.OpenFromFile(DataPath, 0); //Open table "tableName" ITable table = fWs.OpenTable(Sheet); //Dynamic //ITable table = fWs.OpenTable("TroutLakes$"); //Add StandaloneTable IStandaloneTableCollection ISTC = (IStandaloneTableCollection)map; IStandaloneTable SAT = new StandaloneTable(); SAT.Table = table; ISTC.AddStandaloneTable(SAT); //Refresh Activeview mxDoc.ActiveView.Refresh(); mxDoc.UpdateContents(); // Part 3: Join the table to the feature class // Create a memory relationship class IMemoryRelationshipClassFactory memRelFact; IRelationshipClass relClass; memRelFact = new MemoryRelationshipClassFactory(); relClass = memRelFact.Open(JoinName, featureClass, TableFieldName, (IObjectClass)table, FCFieldName, FCName, TableName, esriRelCardinality.esriRelCardinalityOneToMany); // Perform a join IDisplayRelationshipClass dispRC = (IDisplayRelationshipClass)featureLayer; dispRC.DisplayRelationshipClass(relClass, esriJoinType.esriLeftInnerJoin); IDisplayTable dispTable = (IDisplayTable)dispRC; IDatasetName srcName = (dispTable as IDataset).FullName as IDatasetName; IDatasetName destName = new FeatureClassNameClass() as IDatasetName; string LTOutput = Interaction.InputBox("Please enter Feature class name"); destName.Name = LTOutput; IWorkspaceName destWsName = new WorkspaceNameClass(); destWsName.PathName = "Data\\trial.gdb"; destWsName.WorkspaceFactoryProgID = "esriDataSourcesFile.FileGDBWorkspaceFactory"; destName.WorkspaceName = destWsName; IFeatureClassName destFcName = destName as IFeatureClassName; destFcName.FeatureType = esriFeatureType.esriFTSimple; destFcName.ShapeFieldName = "Shape"; destFcName.ShapeType = featureLayer.FeatureClass.ShapeType; var queryFilter = new QueryFilterClass(); queryFilter.SubFields = "*"; queryFilter.WhereClause = "(GNE_Clip.Lake_Town = \"TroutLakes.Lake_Town\")"; ISelectionSet selnSet = null; IGeometryDef geomDef = null; IExportOperation exOp = new ExportOperation(); exOp.ExportFeatureClass((IDatasetName)srcName, queryFilter, selnSet, geomDef, destFcName, 0); mxDoc.ActiveView.Refresh(); mxDoc.UpdateContents(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source); } }
أكثر...
public void JoinLT(string DataPath,string Sheet, int lyrIndex, string JoinName, string TableFieldName,string FCFieldName, string FCName, string TableName) //Export the lakes from the GNE_Layer, to an already defined file geodatabase { try { // Part 1: Define the Environoment IMxDocument mxDoc = (IMxDocument)ArcMap.Application.Document; IMap map = mxDoc.FocusMap; ILayer layer = map.Layer[lyrIndex]; // GNE_Clip IFeatureLayer featureLayer = (IFeatureLayer)layer; IFeatureClass featureClass = featureLayer.FeatureClass; IWorkspaceFactory WsF = new ExcelWorkspaceFactory(); //Open the Excel sheet IFeatureWorkspace fWs = (IFeatureWorkspace)WsF.OpenFromFile(DataPath, 0); //Open table "tableName" ITable table = fWs.OpenTable(Sheet); //Dynamic //ITable table = fWs.OpenTable("TroutLakes$"); //Add StandaloneTable IStandaloneTableCollection ISTC = (IStandaloneTableCollection)map; IStandaloneTable SAT = new StandaloneTable(); SAT.Table = table; ISTC.AddStandaloneTable(SAT); //Refresh Activeview mxDoc.ActiveView.Refresh(); mxDoc.UpdateContents(); // Part 3: Join the table to the feature class // Create a memory relationship class IMemoryRelationshipClassFactory memRelFact; IRelationshipClass relClass; memRelFact = new MemoryRelationshipClassFactory(); relClass = memRelFact.Open(JoinName, featureClass, TableFieldName, (IObjectClass)table, FCFieldName, FCName, TableName, esriRelCardinality.esriRelCardinalityOneToMany); // Perform a join IDisplayRelationshipClass dispRC = (IDisplayRelationshipClass)featureLayer; dispRC.DisplayRelationshipClass(relClass, esriJoinType.esriLeftInnerJoin); IDisplayTable dispTable = (IDisplayTable)dispRC; IDatasetName srcName = (dispTable as IDataset).FullName as IDatasetName; IDatasetName destName = new FeatureClassNameClass() as IDatasetName; string LTOutput = Interaction.InputBox("Please enter Feature class name"); destName.Name = LTOutput; IWorkspaceName destWsName = new WorkspaceNameClass(); destWsName.PathName = "Data\\trial.gdb"; destWsName.WorkspaceFactoryProgID = "esriDataSourcesFile.FileGDBWorkspaceFactory"; destName.WorkspaceName = destWsName; IFeatureClassName destFcName = destName as IFeatureClassName; destFcName.FeatureType = esriFeatureType.esriFTSimple; destFcName.ShapeFieldName = "Shape"; destFcName.ShapeType = featureLayer.FeatureClass.ShapeType; var queryFilter = new QueryFilterClass(); queryFilter.SubFields = "*"; queryFilter.WhereClause = "(GNE_Clip.Lake_Town = \"TroutLakes.Lake_Town\")"; ISelectionSet selnSet = null; IGeometryDef geomDef = null; IExportOperation exOp = new ExportOperation(); exOp.ExportFeatureClass((IDatasetName)srcName, queryFilter, selnSet, geomDef, destFcName, 0); mxDoc.ActiveView.Refresh(); mxDoc.UpdateContents(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source); } }
أكثر...