/// <summary> /// 传输矢量 /// </summary> /// <param name="task"></param> public static void CopyFeatures(string sourceFileName, string destFileName, RenameMode renameMode) { FeatureReadHelper inputReadHelper = new FeatureReadHelper(sourceFileName); FeatureReadHelper outputReadHelper = new FeatureReadHelper(destFileName); string outputNameWithoutExtention = string.Empty; if (renameMode.Equals(RenameMode.Overwrite)) { outputReadHelper.Delete(outputReadHelper.NameWithoutExtension + outputReadHelper.Extension); outputNameWithoutExtention = outputReadHelper.NameWithoutExtension; } else { outputNameWithoutExtention = inputReadHelper.AccumulativeName; } ESRI.ArcGIS.DataManagementTools.CopyFeatures CpyFeat = new ESRI.ArcGIS.DataManagementTools.CopyFeatures(sourceFileName, outputReadHelper.Directory + "\\" + outputNameWithoutExtention); Geoprocessor gp = new Geoprocessor(); gp.OverwriteOutput = true; IGeoProcessorResult gpResult = gp.Execute(CpyFeat, null) as IGeoProcessorResult; if (gpResult == null || gpResult.Status == esriJobStatus.esriJobFailed) { for (int i = 0; i < gpResult.MessageCount; i++) { MessageBox.Show(gpResult.GetMessage(i)); } } }
/// <summary> /// FeatureClass导入GDB /// </summary> /// <param name="in_features">输入FeatureClass</param> /// <param name="gdb_Path">库完整路径</param> /// <param name="feat_Name">库内文件名</param> /// <param name="result">运行结果</param> /// <returns></returns> public static bool ImportFeaturesToGDB(IFeatureClass in_features, string gdb_Path, string feat_Name, out string result) { try { ESRI.ArcGIS.DataManagementTools.CopyFeatures cfs = new ESRI.ArcGIS.DataManagementTools.CopyFeatures(); cfs.in_features = in_features; cfs.out_feature_class = gdb_Path + "//" + GetNameGDB(gdb_Path, feat_Name); Geoprocessor gp = new Geoprocessor(); gp.OverwriteOutput = true; IGeoProcessorResult gpr = gp.Execute(cfs, null) as IGeoProcessorResult; if (gpr != null && gpr.Status == esriJobStatus.esriJobSucceeded) { result = "Success"; return(true); } else { result = "Failure"; return(false); } } catch (Exception e) { result = e.Message; return(false); } }
private void copyFeaturesToolStripMenuItem_Click(object sender, EventArgs e) { ESRI.ArcGIS.DataManagementTools.CopyFeatures copyFeatures = new ESRI.ArcGIS.DataManagementTools.CopyFeatures(); copyFeatures.in_features = fileGDBPath + "\\" + sourceFCName; copyFeatures.out_feature_class = sdePath + "\\" + targetFCName; ExecuteGP(copyFeatures as IGPProcess); }
private string CopyFeatureClass(object featureClass) { try { ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); ESRI.ArcGIS.DataManagementTools.CopyFeatures copyFeatures = new ESRI.ArcGIS.DataManagementTools.CopyFeatures(); copyFeatures.in_features = featureClass; copyFeatures.out_feature_class = AppSingleton.Instance().WorkspacePath + "\\" + "Copy"; gp.AddOutputsToMap = true; gp.OverwriteOutput = true; gp.Execute(copyFeatures, null); return(copyFeatures.out_feature_class.ToString()); } catch (Exception ex) { return(string.Empty); } }
public static void DoSaveSelectedFeatures(Form frmSrc) { if (ArcMap.Document.SelectedLayer == null) { System.Windows.Forms.MessageBox.Show("Select a layer before continuing."); return; } if (frmSrc != null) { frmSrc.TopMost = false; } IFeatureLayer ifl_active = (IFeatureLayer)ArcMap.Document.SelectedLayer; gd.Title = "Save selected features"; gd.ObjectFilter = new GxFilterFeatureClassesClass(); //new GxFilterFeatureClassesClass(); if (gd.DoModalSave(ArcMap.Application.hWnd) == false) { return; } ESRI.ArcGIS.DataManagementTools.CopyFeatures cf = new ESRI.ArcGIS.DataManagementTools.CopyFeatures(); cf.in_features = ifl_active; cf.out_feature_class = gd.FinalLocation.FullName + "\\" + gd.Name; if (frmSrc != null) { frmSrc.TopMost = false; } gp.ExecuteAsync(cf); }
/// <summary> /// GDB导出Shapefile /// </summary> /// <param name="gdb_Path">服务端库完整路径</param> /// <param name="feat_Name">服务端库内文件名</param> /// <param name="outputFolderPath">输出路径</param> /// <param name="outputName">输出名(无需后缀)</param> /// <param name="result">运行结果</param> /// <param name="layer">操作图层</param> /// <returns></returns> public static bool ExportFeaturesFromGDB(string gdb_Path, string feat_Name, string outputFolderPath, string outputName, out string result, out ILayer layer) { try { ESRI.ArcGIS.DataManagementTools.CopyFeatures cfs = new ESRI.ArcGIS.DataManagementTools.CopyFeatures(); cfs.in_features = gdb_Path + "\\" + feat_Name; if (System.IO.Path.GetExtension(outputFolderPath).ToUpper().Equals(".GDB")) { cfs.out_feature_class = outputFolderPath + "\\" + GetNameGDB(outputFolderPath, outputName); } else { cfs.out_feature_class = outputFolderPath + "\\" + GetNameShapeFile(outputFolderPath, feat_Name); } Geoprocessor gp = new Geoprocessor(); gp.OverwriteOutput = true; IGeoProcessorResult gpr = gp.Execute(cfs, null) as IGeoProcessorResult; layer = null; if (gpr != null && gpr.Status == esriJobStatus.esriJobSucceeded) { if (MessageBox.Show("是否将图层加入到当前工程?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { IWorkspaceFactory wsf; if (System.IO.Path.GetExtension(outputFolderPath).ToUpper().Equals(".GDB")) { wsf = new FileGDBWorkspaceFactoryClass(); } else { wsf = new ShapefileWorkspaceFactoryClass(); } IFeatureWorkspace featWs = (IFeatureWorkspace)wsf.OpenFromFile(outputFolderPath, 0); IFeatureLayer featLyr = new FeatureLayerClass(); featLyr.FeatureClass = featWs.OpenFeatureClass(outputName) as IFeatureClass; layer = featLyr as ILayer; if (System.IO.Path.GetExtension(outputFolderPath).ToUpper().Equals(".GDB")) { layer.Name = GetNameGDB(outputFolderPath, outputName); } else { layer.Name = GetNameShapeFile(outputFolderPath, outputName); } } result = "Success"; return(true); } else { result = "Failure"; return(false); } } catch (Exception e) { result = e.Message; layer = null; return(false); } }