/// <summary> /// 两图层进行裁剪运算 /// </summary> /// <param name="inputLayer">被裁剪图层</param> /// <param name="clipLayer">裁剪图层</param> /// <param name="outputFullPath">输出图层完整路径</param> public void ClipByLayer(ILayer inputLayer, ILayer clipLayer, string outputFullPath) { string inputPath = GetLayerPath(inputLayer); string clipPath = GetLayerPath(clipLayer); Clip clipTool = new Clip(); clipTool.in_features = inputPath; clipTool.clip_features = clipPath; clipTool.out_feature_class = outputFullPath; Geoprocessor processor = new Geoprocessor(); IGPProcess process = null; processor.OverwriteOutput = true; process = clipTool; processor.Validate(process, true); processor.Execute(process, null); FileInfo fi = new FileInfo(outputFullPath); string pathDir = fi.Directory.FullName; string name = fi.Name; IWorkspaceFactory wsf = new ShapefileWorkspaceFactoryClass(); IFeatureWorkspace fws = wsf.OpenFromFile(pathDir, 0) as IFeatureWorkspace; IFeatureClass featCls = fws.OpenFeatureClass(name); IFeatureLayer layer = new FeatureLayerClass(); layer.FeatureClass = featCls; layer.Name = featCls.AliasName; m_mapControl.Map.AddLayer(layer as ILayer); }
/// <summary> /// 图层切割栅格数据 /// </summary> /// <param name="rasterLayer">栅格数据图层</param> /// <param name="clipLayer">切割适量图层</param> /// <param name="outputFullPath">切割栅格完整路径</param> public void ClipRasterByLayer(ILayer rasterLayer, ILayer clipLayer, string outputFullPath) { string rasterPath = GetLayerPath(rasterLayer); string clipPath = GetLayerPath(clipLayer); ExtractByMask clipTool = new ExtractByMask(); clipTool.in_raster = rasterPath; clipTool.in_mask_data = clipPath; clipTool.out_raster = outputFullPath; Geoprocessor processor = new Geoprocessor(); IGPProcess process = null; processor.OverwriteOutput = true; process = clipTool; processor.Validate(process, true); processor.Execute(process, null); DirectoryInfo di = new DirectoryInfo(outputFullPath); string rasterDir = di.Parent.FullName; string name = di.Name; IWorkspaceFactory rasterWorkspaceFactory = new RasterWorkspaceFactoryClass(); IRasterWorkspace rasterWorkspace = rasterWorkspaceFactory.OpenFromFile(rasterDir, 0) as IRasterWorkspace; IRasterDataset rasterDataset = rasterWorkspace.OpenRasterDataset(name); IRasterLayer rasterLyr = new RasterLayerClass(); rasterLyr.CreateFromDataset(rasterDataset); m_mapControl.Map.AddLayer(rasterLyr as ILayer); }
private bool RunProcess(IGPProcess inProcess, ITrackCancel inCancel) { bool wasSuccessful = false; //try //{ string toolbox = inProcess.ToolboxName; mLog.Debug("inside run process"); mLog.Debug("the process I want to run is " + inProcess.ToolName); mLog.Debug("the tool box is " + toolbox); myProcessor.OverwriteOutput = true; myProcessor.Execute(inProcess, null); wasSuccessful = ReturnMessages(myProcessor); #if DEBUG //if (!wasSuccessful) // System.Windows.Forms.MessageBox.Show("Data error"); #endif //} //catch (Exception ex) //{ //wasSuccessful = false; //Console.WriteLine(ex.Message); //ReturnMessages(myProcessor); //} return(wasSuccessful); }
/// <summary> /// 执行GP工具 /// </summary> /// <param name="process"></param> /// <returns></returns> private object Execute(IGPProcess process) { m_gp.OverwriteOutput = true; m_gp.TemporaryMapLayers = false; object sev = null; object obj = null; try { obj = m_gp.Execute(process, null); object subObj = null; string msg = m_gp.GetMessages(ref subObj); SendMessage(enumMessageType.OperationalLog, msg); } catch (Exception ex) { SendMessage(enumMessageType.Exception, ex.ToString()); string msg = m_gp.GetMessage(2); } finally { if (obj != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(obj); } } return(obj); }
private IFeatureClass RunProcessGetFeatureClass(IGPProcess inProcess, ITrackCancel inCancel, string ignoreMessage) { IFeatureClass fc = null; IQueryFilter qf = null; IGeoProcessorResult result = null; IGPUtilities util = null; try { string toolbox = inProcess.ToolboxName; mLog.Debug("inside run process"); mLog.Debug("the process I want to run is " + inProcess.ToolName); mLog.Debug("the tool box is " + toolbox); myProcessor.OverwriteOutput = true; result = (IGeoProcessorResult)myProcessor.Execute(inProcess, null); ReturnMessages(myProcessor); //if result is null then there are no viable areas if (result != null) { util = new GPUtilitiesClass(); util.DecodeFeatureLayer(result.GetOutput(0), out fc, out qf); ReturnMessages(myProcessor, ignoreMessage); } } catch (Exception ex) { eLog.Debug(ex); ReturnMessages(myProcessor); } return(fc); }
private void ExecuteGP(IGPProcess GPProcess) { Geoprocessor gp = new Geoprocessor { OverwriteOutput = true }; try { IGeoProcessorResult2 result = gp.Execute(GPProcess, null) as IGeoProcessorResult2; } catch (Exception ex) { MessageBox.Show(ex.Message, "GP Error"); } finally { System.Text.StringBuilder sb = new System.Text.StringBuilder(); for (int i = 0; i < gp.MessageCount; i++) { sb.AppendLine(gp.GetMessage(i)); } if (sb.Capacity > 0) { MessageBox.Show(sb.ToString(), "GP Messages"); } } }
private static bool RunTool(IGPProcess process, ITrackCancel TC, out IEnumerable <string> messages) { if (gp == null) { gp = new Geoprocessor { AddOutputsToMap = false }; gp.SetEnvironmentValue(environmentName, temporaryWorkspace); } gp.OverwriteOutput = true; // Set the overwrite output option to true bool result = true; try { IGeoProcessorResult pResult = (IGeoProcessorResult)gp.Execute(process, null); } catch (Exception ex) { Console.WriteLine(ex.Message); result = false; } messages = ReturnMessages(gp).ToArray(); return(result); }
public void Dispose() { if (this.Process != null) { //System.Runtime.InteropServices.Marshal.ReleaseComObject(this.Process); //GIS.ArcGIS.TokayWorkspace.ComRelease(this.m_process); this.m_process = null; } }
/// <summary> /// Private wrapper used to execute an IGPProcess gpTool, returning either zero /// if the tool's execution succeedes without any errors or the MaxSeverityErrCode /// if one or more errors are realized by the geoprocessor. /// param name="gpTool" the geoprocessing tool /// </summary> static private void Execute(IGPProcess gpTool) { geoprocessor.Execute(gpTool, null); if (geoprocessor.MaxSeverity < (int)MaxSeverityErrCode) retVal = 0; else retVal = geoprocessor.MaxSeverity; }
/// <summary> /// Truncates and appends input feature class /// </summary> /// <param name="originFC">Origin feature class</param> /// <param name="originWS">origin workspace</param> /// <param name="targetFC">destination feature class</param> /// <param name="targetWS">destination workspace</param> private void TruncateAppendFeatureClass(object originFC, string originWS, object targetFC, string targetWS) { IFeatureClass truncFC; IGPProcess truncateGP = FireGeoprocessingTools.GetTruncateFeatureTableGP(targetFC); RunGeoprocess(ref truncateGP, targetWS, true, 0, out truncFC); IGPProcess appendGP = FireGeoprocessingTools.GetAppendFeatureTableGP(originFC, targetFC); RunGeoprocess(ref appendGP, targetWS); }
/// <summary> /// Runnings generic geoprocess passed from FireGeoprocessingTools static class. /// </summary> /// <param name="inGPObj">In geoprocessing object to run.</param> /// <param name="workspacePath">Workspace path to use</param> /// <param name="overwriteOutput">bool set to true if output is to be overwritten</param> private void RunGeoprocess(ref IGPProcess inGPObj, string workspacePath, bool overwriteOutput = true) { using (FeatureProcessingFactory featureProcessing = new FeatureProcessingFactory(workspacePath, overwriteOutput)) { RaiseLogEvent($"Running {inGPObj.ToolName}"); featureProcessing.OnProcessChangedEvent += base.RaiseProcessChangedEvent; featureProcessing.OnProcessExceptionEvent += this.RaiseExceptionEvent; featureProcessing.RunGeoprocessingOperation(inGPObj); featureProcessing.OnProcessChangedEvent -= base.RaiseProcessChangedEvent; featureProcessing.OnProcessExceptionEvent -= this.RaiseExceptionEvent; } }
/// <summary> /// Private wrapper used to execute an IGPProcess gpTool, returning either zero /// if the tool's execution succeedes without any errors or the MaxSeverityErrCode /// if one or more errors are realized by the geoprocessor. /// param name="gpTool" the geoprocessing tool /// </summary> static private void Execute(IGPProcess gpTool) { geoprocessor.Execute(gpTool, null); if (geoprocessor.MaxSeverity < (int)MaxSeverityErrCode) { retVal = 0; } else { retVal = geoprocessor.MaxSeverity; } }
public static bool Excute(IGPProcess tool) { try { _gp.Execute(tool, null); }catch (COMException comexc) { var error = string.Format("GP错误代码:{0},详情:{1}", comexc.ErrorCode, comexc.Message); Console.WriteLine(error); return(false); } return(true); }
/// <summary> /// Runnings generic geoprocess passed from FireGeoprocessingTools static class. /// </summary> /// <param name="inGPObj">In geoprocessing object to run.</param> /// <param name="workspacePath">Workspace path to use</param> /// <param name="returnIdx">index of return object.</param> /// <param name="overwriteOutput">bool set to true if output is to be overwritten</param> /// <param name="result">IFeatureClass object returned from GPOperation</param> private void RunGeoprocess(ref IGPProcess inGPObj, string workspacePath, bool overwriteOutput, int returnIdx, out IFeatureClass result) { using (FeatureProcessingFactory featureProcessing = new FeatureProcessingFactory(workspacePath, overwriteOutput)) { RaiseLogEvent($"Running {inGPObj.ToolName}"); featureProcessing.OnProcessChangedEvent += base.RaiseProcessChangedEvent; featureProcessing.OnProcessExceptionEvent += this.RaiseExceptionEvent; featureProcessing.RunGeoprocessingOperation(inGPObj); result = featureProcessing.GPResultToFeatureClass(returnIdx); featureProcessing.OnProcessChangedEvent -= base.RaiseProcessChangedEvent; featureProcessing.OnProcessExceptionEvent -= this.RaiseExceptionEvent; } }
//private string GetPathByName(string name) //{ // IMap pMap = pMapControl.Map; // IEnumLayer pEnumLayer = pMap.get_Layers(null, true); // pEnumLayer.Reset(); // ILayer pLayer = pEnumLayer.Next(); // while (pLayer != null) // { // //cobox.Items.Add(pLayer.Name); // // Console.WriteLine(pLayer.Name); // pLayer = pEnumLayer.Next(); // } //} private void RunTool(Geoprocessor geoprocessor, IGPProcess process, ITrackCancel TC) { // Set the overwrite output option to true geoprocessor.OverwriteOutput = true; try { geoprocessor.Execute(process, null); ReturnMessages(geoprocessor); } catch (Exception err) { Console.WriteLine(err.Message); ReturnMessages(geoprocessor); } }
//------------------------------------------------------------------------- private static bool RunTool(Geoprocessor gp, IGPProcess process, ITrackCancel TC) { gp.OverwriteOutput = true; // Set the overwrite output option to true try { IGeoProcessorResult pResult = (IGeoProcessorResult)gp.Execute(process, null); ReturnMessages(gp); } catch (Exception ex) { Console.WriteLine(ex.Message); ReturnMessages(gp); return(false); } return(true); }
/// <summary> /// 运行地理分析工具 /// </summary> /// <param name="gp"></param> /// <param name="process"></param> /// <param name="trackCancel"></param> /// <returns></returns> public static IGeoProcessorResult2 RunGeoProcessor(Geoprocessor gp, IGPProcess process, ITrackCancel trackCancel) { IGeoProcessorResult2 gpResult = null; try { gpResult = gp.Execute(process, trackCancel) as IGeoProcessorResult2; //执行分析 return gpResult; } catch (Exception ex) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format("#RunGP:{0};{1}", ex.Message, ex.StackTrace)); #endif return gpResult; } }
internal static void RunTool(Geoprocessor geoprocessor, IGPProcess process, ITrackCancel TC) { // Set the overwrite output option to true geoprocessor.OverwriteOutput = true; // Execute the tool try { geoprocessor.Execute(process, TC); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); throw; } }
//判断gp运行 private bool RunTool(Geoprocessor geoprocessor, IGPProcess process) { // Set the overwrite output option to true geoprocessor.OverwriteOutput = true; try { geoprocessor.Execute(process, null); return(true); } catch (Exception err) { Console.WriteLine(err.Message); return(false); } }
private void ExecuteProcess(IGPProcess gpProcess) { IGeoProcessorResult result = null; try { result = gp.Execute(gpProcess, null) as IGeoProcessorResult; }catch (Exception ex) { throw new ApplicationException("执行过程中出现错误:" + ex.Message, ex); } if (result == null || result.Status == ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobFailed) { object srv = 2; throw new ApplicationException("执行过程中出现错误:" + gp.GetMessages(ref srv)); } }
private static bool Excute(IGPProcess tool) { Geoprocessor gp = new Geoprocessor(); gp.OverwriteOutput = true; try { gp.Execute(tool, null); } catch { object sev1 = 2; gp.AddError(gp.GetMessages(ref sev1)); return(false); } return(true); }
/// <summary> /// 运行地理分析工具 /// </summary> /// <param name="gp"></param> /// <param name="process"></param> /// <param name="trackCancel"></param> /// <returns></returns> public static IGeoProcessorResult2 RunGeoProcessor(Geoprocessor gp, IGPProcess process, ITrackCancel trackCancel) { IGeoProcessorResult2 gpResult = null; try { gpResult = gp.Execute(process, trackCancel) as IGeoProcessorResult2; //执行分析 return(gpResult); } catch (Exception ex) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format("#RunGP:{0};{1}", ex.Message, ex.StackTrace)); #endif return(gpResult); } }
/// <summary> /// 两面相交 /// </summary> private void intersect() { //两面相交 ESRI.ArcGIS.Geoprocessor.Geoprocessor GP = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); ESRI.ArcGIS.AnalysisTools.Intersect intersect = new ESRI.ArcGIS.AnalysisTools.Intersect(); intersect.in_features = @"C:\Users\航\Desktop\同济新村shp数据\同济新村房屋.shp;C:\Users\航\Desktop\同济新村shp数据\生成地块.shp"; intersect.out_feature_class = @"C:\Users\航\Desktop\同济新村shp数据\intersect.shp"; IGPProcess GProcess1 = intersect; GP.Execute(GProcess1, null); //如果显示 //Form1.mainForm.axMapControl1.AddShapeFile(@"C:\Users\航\Desktop\同济新村shp数据\", "intersect.shp"); //Form1.mainForm.axMapControl1.Refresh(); }
/// <summary> /// Runs a Geoprocessing tool. /// </summary> /// <param name="geoprocessor">The ArcGIS Geoprocessor defining the environment the Geoprocessing Tool will run in.</param> /// <param name="process">The Geoprocessing tool to run.</param> /// <returns>The result object of the Geoprocessing tool.</returns> public static object RunGpTool(Geoprocessor geoprocessor, IGPProcess process) { object result = null; try { bool tryAgain = false; int retryCount = 0; int maxRetries = 1; do { retryCount++; try { geoprocessor.ProgressChanged += Geoprocessor_ProgressChanged; geoprocessor.MessagesCreated += Geoprocessor_MessagesCreated; IGeoProcessorResult2 geoprocessorResult = geoprocessor.Execute(process, null) as IGeoProcessorResult2; result = geoprocessorResult.ReturnValue; tryAgain = false; } catch (Exception ex) { if (retryCount <= maxRetries) { tryAgain = true; } else { throw new Exception("Geoprocessing tool " + process.ToolName + " failed after " + retryCount + " attempts.", ex); } } }while (tryAgain); return(result); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.GetType().FullName + ": " + ex.Message); throw; } }
public static bool RunTool(Geoprocessor geoprocessor, IGPProcess process, ITrackCancel TC) { // Set the overwrite output option to true geoprocessor.OverwriteOutput = true; // Execute the tool try { geoprocessor.Execute(process, null); ReturnMessages(geoprocessor); return(true); } catch (Exception err) { MessageBox.Show(err.Message); ReturnMessages(geoprocessor); return(false); } }
protected virtual void runTool(Geoprocessor geoprocessor, IGPProcess process, ITrackCancel TC) { // Set the overwrite output option to true geoprocessor.OverwriteOutput = true; // Execute the tool try { geoprocessor.Execute(process, TC); ReturnMessages(geoprocessor); } catch (Exception err) { Console.WriteLine(err.Message); ReturnMessages(geoprocessor); } }
/// <summary> /// 运行GP服务,捕捉异常和消息 /// </summary> /// <param name="geoprocessor"></param> /// <param name="process"></param> private void Runtool(Geoprocessor geoprocessor, IGPProcess process) { try { IGeoProcessorResult result = null; result = geoprocessor.Execute(process, null) as IGeoProcessorResult; if (result.Status != esriJobStatus.esriJobSucceeded) { MessageBox.Show("处理失败!"); } } catch (Exception err) { MessageBox.Show(err.ToString()); ReturnMessages(geoprocessor); return; } }
protected virtual void runTool(Geoprocessor geoprocessor, string name, IGPProcess process, IVariantArray param, ITrackCancel TC) { // Set the overwrite output option to true geoprocessor.OverwriteOutput = true; // Execute the tool try { geoprocessor.Execute(name, param, TC);//"Clip_analysis" ReturnMessages(geoprocessor); } catch (Exception err) { Console.WriteLine(err.Message); ReturnMessages(geoprocessor); } }
private static bool RunTool(Geoprocessor gp, IGPProcess process, ITrackCancel TC, IEnumerable <string> messages) { gp.OverwriteOutput = true; // Set the overwrite output option to true bool result = true; try { IGeoProcessorResult pResult = (IGeoProcessorResult)gp.Execute(process, null); } catch (Exception ex) { Console.WriteLine(ex.Message); result = false; } messages = ReturnMessages(gp); return(result); }
/// <summary> /// 执行GP,并返回处理结果 /// </summary> /// <param name="gProcessor">GP对象</param> /// <param name="process">GP工具</param> /// <param name="trackCancel">取消对象</param> /// <returns>处理结果</returns> public static IGeoProcessorResult ExecuteWithResult(Geoprocessor gProcessor, IGPProcess process, ITrackCancel trackCancel) { IGeoProcessorResult geoResult = null; gProcessor.OverwriteOutput = true; //是否覆盖 try { geoResult = (IGeoProcessorResult)gProcessor.Execute(process, null); ReturnMessages(gProcessor); } catch (Exception ex) { MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace); ReturnMessages(gProcessor); //当调试正确后注释本行 } return(geoResult); }
/// <summary> /// 调用GP执行具体的tool /// </summary> /// <param name="process"></param> /// <returns></returns> private static bool RunGPTool(IGPProcess process) { try { Geoprocessor GP = new Geoprocessor(); GP.OverwriteOutput = true; IGeoProcessorResult result = (IGeoProcessorResult)GP.ExecuteAsync(process); if (result != null && result.Status == ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded) { return(true); } return(false); } catch { throw; } }
/// <summary> /// Copies feature class or dataset to SDE Workspace /// </summary> /// <param name="originDataName">name of origin dataset to be copied</param> /// <param name="originWS">name of origin workspace</param> /// <param name="destinationName">output target to copy</param> /// <param name="destinationPath">name of target workspace to copy to</param> public void CopyToSDEWorkspace(string originDataName, string originWS, string destinationName, string destinationPath, bool deleteExisting) { RaiseLogEvent($"Copying {originDataName}"); if (deleteExisting) { RaiseLogEvent($"Deleting {originDataName}"); IGPProcess deleteGP = FireGeoprocessingTools.GetDeleteFeatureClassGP(destinationName); RunGeoprocess(ref deleteGP, destinationPath); } else { IGPProcess renameGP = FireGeoprocessingTools.GetRenameGP(destinationName, destinationName + "_OLD"); RunGeoprocess(ref renameGP, destinationPath); } IGPProcess copyGP = FireGeoprocessingTools.GetCopyDataGP($"{originWS}\\{originDataName}", $"{destinationName}"); RunGeoprocess(ref copyGP, destinationPath, true); }
/// <summary> /// /// </summary> /// <param name="strInput"></param> /// <param name="outPut"></param> /// <param name="isToFile"></param> /// <param name="strFormat">当isToFile为Ture时,可设置此值,默认值为TIFF,可选值:BMP、JPEG、PNG、GIF、TIFF、IMAGINE、GRID</param> /// <returns></returns> public static bool CopyRaster(string strInput, string outPut, bool isToFile, string strFormat) { try{ IGPProcess gpTool = null; if (isToFile) { RasterToOtherFormat gpToOther = new RasterToOtherFormat(); gpToOther.Input_Rasters = strInput; gpToOther.Output_Workspace = outPut; gpToOther.Raster_Format = strFormat; gpTool = gpToOther; } else { RasterToGeodatabase gpToGDB = new RasterToGeodatabase(); gpToGDB.Input_Rasters = strInput; gpToGDB.Output_Geodatabase = outPut; gpTool = gpToGDB; } Geoprocessor geoProcessor = new Geoprocessor(); geoProcessor.OverwriteOutput = true; IGeoProcessorResult gpResult = geoProcessor.Execute(gpTool, null) as IGeoProcessorResult; //System.Runtime.InteropServices.Marshal.FinalReleaseComObject(geoProcessor); return(gpResult.Status == esriJobStatus.esriJobSucceeded); } catch (Exception exp) { ErrorMessage = exp.Message; return(false); } }
/// <summary> /// runs the geoprocessor given a process /// </summary> /// <param name="process">a specified process</param> /// <returns>geoprocessing messages</returns> private IGeoProcessorResult gpExecute(IGPProcess process) { return (IGeoProcessorResult)gp.Execute(process, null); }
public static bool RunTool(Geoprocessor geoprocessor, IGPProcess process, ITrackCancel TC) { // Set the overwrite output option to true geoprocessor.OverwriteOutput = true; // Execute the tool try { geoprocessor.Execute(process, null); ReturnMessages(geoprocessor); return true; } catch (Exception err) { MessageBox.Show(err.Message); ReturnMessages(geoprocessor); return false; } }
public static bool RunTool(ESRI.ArcGIS.Geoprocessor.Geoprocessor geoprocessor, IGPProcess process, ITrackCancel TC) { geoprocessor.OverwriteOutput = true; geoprocessor.ClearMessages(); try { object obj2 = geoprocessor.Execute(process, TC); ReturnMessages(geoprocessor); return(true); } catch (Exception exception) { MessageBox.Show(exception.Message); ReturnMessages(geoprocessor); return(false); } }
private static bool RunTool(Geoprocessor geoprocessor, IGPProcess process, ITrackCancel TC) { // Set the overwrite output option to true geoprocessor.OverwriteOutput = true; // Execute the tool try { geoprocessor.Execute(process, null); return ReturnMessages(geoprocessor); } catch (Exception err) { Debug.WriteLine(err.Message); ReturnMessages(geoprocessor); } return false; }
/// <summary> /// 运行GP工具箱 /// </summary> /// <param name="geoprocessor"></param> /// <param name="process"></param> /// <param name="TC"></param> private static void RunTool(Geoprocessor geoprocessor, IGPProcess process, ITrackCancel TC) { // Set the overwrite output option to true geoprocessor.OverwriteOutput = true; try { geoprocessor.Execute(process, null); ReturnMessages(geoprocessor); } catch (Exception err) { MessageBox.Show(err.Message); ReturnMessages(geoprocessor); } }