} // getFCNames public void doWork() { Log.p("doWork started..."); String sdeconnfname = mSdeConnFileName; // "c:\\t\\test.sde"; String tabnames = mTabName; // "T.TAB1,T.TAB2"; Log.p("Open the source gdb"); IWorkspaceFactory wspFact = new SdeWorkspaceFactoryClass(); IWorkspace wsp = wspFact.OpenFromFile(sdeconnfname, 0); Log.p("Get FC names"); IEnumNameEdit edtNames = getFCNames(wsp, tabnames); IEnumName names = (IEnumName)edtNames; Log.p("Create a scratch workspace factory"); IScratchWorkspaceFactory scrWspFact = new ScratchWorkspaceFactoryClass(); IWorkspace scrWsp = scrWspFact.CreateNewScratchWorkspace(); IDataset dset = (IDataset)scrWsp; IName scrWspName = dset.FullName; Log.p("Create a Transfer object and a name mapping"); IGeoDBDataTransfer trans = new GeoDBDataTransferClass(); IEnumNameMapping nameMaps = null; Boolean hasConflicts = trans.GenerateNameMapping( names, scrWspName, out nameMaps); if (hasConflicts) { throw new ArgumentException("Name mapping has conflicts."); } bool expData = mNeedData; string fname = mExpFileName; bool getMeta = mNeedMeta; bool compressed = false; bool binaryGeom = true; IGdbXmlExport exp = new GdbExporterClass(); if (expData == false) { Log.p(String.Format("Export schema (u need sdeexport for data); file [{0}], metadata [{1}]", fname, getMeta)); exp.ExportDatasetsSchema(nameMaps, fname, compressed, getMeta); } else { Log.p(String.Format("Export schema&data; file [{0}], metadata [{1}]", fname, getMeta)); exp.ExportDatasets(nameMaps, fname, binaryGeom, compressed, getMeta); } Log.p("OK, xml writed.", "both"); } // method doWork
internal static IEnumName RicavaDatasetNameEnum(List <IName> nameList) { // Create the enumerator and cast it to the IEnumNameEdit interface. IEnumName enumName = new NamesEnumerator(); IEnumNameEdit enumNameEdit = (IEnumNameEdit)enumName; // Add the input name objects to the enumerator and return it. foreach (IName name in nameList) { enumNameEdit.Add(name); } return(enumName); }
/// <summary> /// Transfers the feature class (and all relationships) to the specified workspace, while preserving the OBJECTID /// values. /// </summary> /// <param name="source">The source.</param> /// <param name="name">The name feature class in the transfer.</param> /// <param name="workspace">The workspace.</param> /// <param name="conflicts">if set to <c>true</c> has conflicts with the export.</param> /// <param name="enumNameMapping">The enum name mapping.</param> /// <returns> /// Returns a <see cref="IFeatureClass" /> representing the feature class in the target workspace. /// </returns> public static IFeatureClass Transfer(this IFeatureClass source, string name, IWorkspace workspace, out bool conflicts, out IEnumNameMapping enumNameMapping) { IDataset ds = (IDataset)source; IName fromName = ds.Workspace.Define(ds.Name, new FeatureClassNameClass()); IEnumName fromNames = new NamesEnumeratorClass(); IEnumNameEdit edit = (IEnumNameEdit)fromNames; edit.Add(fromName); ds.Workspace.Transfer(workspace, fromNames, out conflicts, out enumNameMapping); if (!conflicts) { return(workspace.GetFeatureClass(name)); } return(null); }
public void TansferFileGDBToSDE(string fileGDBPath, string sourceFCName) { // Create workspace name objects. IWorkspaceName sourceWorkspaceName = getWorkspaceName("esriDataSourcesGDB.FileGDBWorkspaceFactory", fileGDBPath); // Create a name object for the target (SDE) workspace and open it. IWorkspaceName targetWorkspaceName = getWorkspaceName("esriDataSourcesGDB.SdeWorkspaceFactory", sdePath); IName targetName = (IName)targetWorkspaceName; // Create a name object for the source dataset. IFeatureClassName sourceFeatureClassName = getFeatureClassName(sourceWorkspaceName, sourceFCName); IName sourceName = (IName)sourceFeatureClassName; // 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(); // Check for conflicts. if (conflictsFound) { // Iterate through each name mapping. INameMapping nameMapping = null; while ((nameMapping = enumNameMapping.Next()) != null) { // Resolve the mapping's conflict (if there is one). if (nameMapping.NameConflicts) { nameMapping.TargetName = nameMapping.GetSuggestedName(targetName); } // See if the mapping's children have conflicts. IEnumNameMapping childEnumNameMapping = nameMapping.Children; if (childEnumNameMapping != null) { childEnumNameMapping.Reset(); // Iterate through each child mapping. INameMapping childNameMapping = null; while ((childNameMapping = childEnumNameMapping.Next()) != null) { if (childNameMapping.NameConflicts) { childNameMapping.TargetName = childNameMapping.GetSuggestedName(targetName); } } } } } // Start the transfer. geoDBDataTransfer.Transfer(enumNameMapping, targetName); }
private void btnOK_Click(object sender, EventArgs e) { //首先进行坐标系x,y变换 //string fileExpTran;//进行x,y做表转换后输出的tiff文件存储路径,用这一文件在进行后期的Z转换 //fileExpTran = System.IO.Path.GetDirectoryName(LayerExpName) +"\\"+ System.IO.Path.GetFileNameWithoutExtension(LayerExpName)+"XY.tif"; //try //{ // if (NorthEastToEastNorth(pRasterLayer, LayerExpName)) // { // RasterLayerClass rasterlayer = new RasterLayerClass(); // rasterlayer.CreateFromFilePath(LayerExpName); // IRaster2 pRaster2 = rasterlayer.Raster as IRaster2; // IRasterDataset2 pRasterDataset = pRaster2.RasterDataset as IRasterDataset2; // ChangeRasterValue(pRasterDataset, -1, 0); // pMapControl.AddLayer(rasterlayer as ILayer); // this.Close(); // } //} //catch (System.Exception ex) //{ // MessageBox.Show(ex.Message); //} try { IFeatureClass pFC = pFeatureLayer.FeatureClass; IDataset pDS = pFC as IDataset; IWorkspace pWS = pDS.Workspace; string filedir = pWS.PathName; string fdestname = System.IO.Path.GetFileNameWithoutExtension(txtFeatureName.Text); ClsGDBDataCommon CGD = new ClsGDBDataCommon(); IWorkspace pTargetWS = CGD.OpenFromShapefile(txtLayerExp.Text); IWorkspace2 workspace2 = pTargetWS as IWorkspace2; if (workspace2.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureClass, fdestname)) { MessageBox.Show("目标文件已存在!"); return; } //shape文件直接拷贝后再修改 if (pDS.CanCopy() == true) { pDS.Copy(txtFeatureName.Text, pTargetWS); IFeatureWorkspace pFW = pTargetWS as IFeatureWorkspace; pTargetFeatureClass = pFW.OpenFeatureClass(txtFeatureName.Text); TransCoordiante(pFW as IWorkspace, pTargetFeatureClass); } //表示为gdb的feature,只能往gdb拷贝 else { // Create workspace name objects. IWorkspaceName sourceWorkspaceName = new WorkspaceNameClass(); IWorkspaceName targetWorkspaceName = new WorkspaceNameClass(); IName targetName = (IName)targetWorkspaceName; // Set the workspace name properties. sourceWorkspaceName.PathName = pWS.PathName; sourceWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesGDB.FileGDBWorkspaceFactory"; // targetWorkspaceName.PathName = @"PartialMontgomery.gdb"; targetWorkspaceName.PathName = txtLayerExp.Text; targetWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesGDB.FileGDBWorkspaceFactory"; //if (txtLayerExp.Text.Length>4 && txtLayerExp.Text.Substring(txtLayerExp.Text.Length-4,4) == ".gdb") //{ // targetWorkspaceName.WorkspaceFactoryProgID = // "esriDataSourcesGDB.FileGDBWorkspaceFactory"; //} //else //{ // targetWorkspaceName.WorkspaceFactoryProgID = // "esriDataSourcesFile.ShapefileWorkspaceFactory"; //} // 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 = pDS.BrowseName; 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(); //修改拷贝的文件名 INameMapping nameMapping = enumNameMapping.Next(); if ((nameMapping != null)) { nameMapping.TargetName = txtFeatureName.Text; } // Check for conflicts. //if (conflictsFound) //{ // // Iterate through each name mapping. // INameMapping nameMapping = null; // while ((nameMapping = enumNameMapping.Next()) != null) // { // // Resolve the mapping's conflict (if there is one). // if (nameMapping.NameConflicts) // { // nameMapping.TargetName = nameMapping.GetSuggestedName(targetName); // } // // See if the mapping's children have conflicts. // IEnumNameMapping childEnumNameMapping = nameMapping.Children; // if (childEnumNameMapping != null) // { // childEnumNameMapping.Reset(); // // Iterate through each child mapping. // INameMapping childNameMapping = null; // while ((childNameMapping = childEnumNameMapping.Next()) != null) // { // if (childNameMapping.NameConflicts) // { // childNameMapping.TargetName = childNameMapping.GetSuggestedName // (targetName); // } // } // } // } //} // Start the transfer. geoDBDataTransfer.Transfer(enumNameMapping, targetName); IFeatureWorkspace pFW = CGD.OpenFromFileGDB(txtLayerExp.Text) as IFeatureWorkspace; pTargetFeatureClass = pFW.OpenFeatureClass(txtFeatureName.Text); TransCoordiante(pFW as IWorkspace, pTargetFeatureClass); } if (pTargetFeatureClass != null) { //添加到图层中 IFeatureLayer featureLayer = new FeatureLayerClass(); featureLayer.FeatureClass = pTargetFeatureClass; featureLayer.Name = fdestname; pMapControl.AddLayer(featureLayer as ILayer); pMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); } this.DialogResult = DialogResult.OK; } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }