private void button2_Click(object sender, EventArgs e) { ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); gp.OverwriteOutput = true; double bufferDistance = 0.0; bufferDistance = Convert.ToDouble(textBox1.Text); ILayer pLayer = new FeatureLayerClass(); for (int i = 0; i < global.pMap.LayerCount - 1; i++) { if (global.pMap.Layer[i].Name == comboBox2.Text) { pLayer = global.pMap.Layer[i]; } } bufferfilesave = false; ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(pLayer, textBox2.Text, textBox2.Text.Trim() + " " + (comboBox2.SelectedItem)); buffer.dissolve_option = "ALL"; //这个要设成ALL,否则相交部分不会融合 buffer.line_side = "FULL"; //默认是"FULL",最好不要改否则出错 buffer.line_end_type = "ROUND"; //默认是"ROUND",最好不要改否则出错 ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult results = (ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult)(gp.Execute(buffer, null)); if ((int)results.Status != 4) { MessageBox.Show("缓冲区分析失败!"); } else { MessageBox.Show("缓冲区分析成功!"); bufferfilesave = true; } bufferShpPath = textBox2.Text; }
/// <summary> /// Run the Geoprocessing model /// </summary> /// <param name="modelParametersHybridDictionary">A HybridDictionary that contains all of the arguments to run the model</param> /// <returns>A message of how well the model executed</returns> /// <remarks></remarks> public static System.String ExecuteCustomGeoprocessingFunction(System.Collections.Specialized.HybridDictionary modelParametersHybridDictionary) { try { // Create a Geoprocessor object ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); // Set the OverwriteOutput setting to True gp.OverwriteOutput = true; // Create a new instance of our custom model MYCUSTOMTOOLBOX.GolfFinder myModel = new MYCUSTOMTOOLBOX.GolfFinder(); // Set the custom models parameters. myModel.BufferDistance = modelParametersHybridDictionary["BufferDistance"]; myModel.AIRPORT = modelParametersHybridDictionary["Airports"]; myModel.GOLF = modelParametersHybridDictionary["Golf"]; myModel.AirportBuffer = modelParametersHybridDictionary["AirportBuffer"]; myModel.Golf_Courses_Near_Airports = modelParametersHybridDictionary["GolfNearAirports"]; // Execute the model and obtain the result from the run ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult geoProcessorResult = (ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult)gp.Execute(myModel, null); if (geoProcessorResult == null) { // We have an error running the model. // If the run fails a Nothing (VB.NET) or null (C#) is returned from the gp.Execute object sev = 2; string messages = gp.GetMessages(ref sev); return(messages); } else { // The model completed successfully return("Output successful. The shapefiles are locacted at: " + geoProcessorResult.ReturnValue.ToString()); } } catch (Exception ex) { // Catch any other errors return("Error running the model. Debug the application and test again."); } }