/// <summary> /// Handles the ToolExecuted event. All tools end by firing this event. If the tool executed successfully /// the next tool in the queue is removed and submitted for execution. If unsuccessful, geoprocessing is terminated, /// an error message is written to the ListViewControl and the is queue cleared. After the final tool has executed /// the result layer is added to the Map. /// </summary> void _gp_ToolExecuted(object sender, ToolExecutedEventArgs e) { IGeoProcessorResult2 gpResult = (IGeoProcessorResult2)e.GPResult; try { //The first GP tool has completed, if it was successful process the others if (gpResult.Status == esriJobStatus.esriJobSucceeded) { listView1.Items.Add(new ListViewItem(new string[2] { "ToolExecuted", gpResult.Process.Tool.Name }, "success")); //Execute next tool in the queue if (_myGPToolsToExecute.Count > 0) { _gp.ExecuteAsync(_myGPToolsToExecute.Dequeue()); } //If last tool has executed add the output layer to the map else { IFeatureClass resultFClass = _gp.Open(gpResult.ReturnValue) as IFeatureClass; IFeatureLayer resultLayer = new FeatureLayerClass(); resultLayer.FeatureClass = resultFClass; resultLayer.Name = resultFClass.AliasName; //Add the result to the map axMapControl1.AddLayer((ILayer)resultLayer, 2); axTOCControl1.Update(); //add the result layer to the List of result layers _resultsList.Add(resultLayer); } } //If the GP process failed, do not try to process any more tools in the queue else if (gpResult.Status == esriJobStatus.esriJobFailed) { //The actual GP error message will be output by the MessagesCreated event handler listView1.Items.Add(new ListViewItem(new string[2] { "ToolExecuted", gpResult.Process.Tool.Name + " failed, any remaining processes will not be executed." }, "error")); //Empty the queue _myGPToolsToExecute.Clear(); } } catch (Exception ex) { listView1.Items.Add(new ListViewItem(new string[2] { "ToolExecuted", ex.Message }, "error")); } }
public PolygonsPartitionAggregation(string dataPath,string dataName,string resultPath,string gradeField) { m_GP = new Geoprocessor(); MakeFeatureLayer makefeaturelayer = new MakeFeatureLayer(); makefeaturelayer.in_features = dataPath + dataName + ".shp"; makefeaturelayer.out_layer = "origin_lyr"; m_GP.Execute(makefeaturelayer, null); IFeatureLayer fealyr = m_GP.Open(makefeaturelayer.out_layer) as IFeatureLayer; m_FeaCls = fealyr.FeatureClass; m_PartitionField = gradeField; m_WorkingPath = resultPath; }