本文主要是介绍AE调用GP,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
借用别人的东西,将这两种方法放在一起:
第一种,分别设置参数:
//添加命名空间using ESRI.ArcGIS.esriSystem;using ESRI.ArcGIS.Geoprocessor;//实现button click方法private void button1_Click(object sender, EventArgs e){//构造GeoprocessorGeoprocessor gp = new Geoprocessor();//设置参数ESRI.ArcGIS.AnalysisTools.Intersect intersect = new ESRI.ArcGIS.AnalysisTools.Intersect();intersect.in_features = @"F:\foshan\Data\wuqutu_b.shp;F:\foshan\Data\world30.shp";intersect.out_feature_class = @"E:\intersect.shp";intersect.join_attributes = "ONLY_FID";//执行Intersect工具RunTool(gp, intersect, null);}private void RunTool(Geoprocessor geoprocessor, IGPProcess process, ITrackCancel TC){// Set the overwrite output option to truegeoprocessor.OverwriteOutput = true;try{geoprocessor.Execute(process, null);ReturnMessages(geoprocessor);}catch (Exception err){Console.WriteLine(err.Message);ReturnMessages(geoprocessor);}}// Function for returning the tool messages.private void ReturnMessages(Geoprocessor gp){string ms = "";if (gp.MessageCount > 0){for (int Count = 0; Count <= gp.MessageCount - 1; Count++){ms += gp.GetMessage(Count);}}
另一种添加参数:
//1-定义GeoProcessor对象Geoprocessor gp = new Geoprocessor();object sev = null;//2-设置参数gp.OverwriteOutput = true;//3-设置工具箱所在的路径gp.AddToolbox(@"F:\lib_test\AirportsAndGolf.tbx");//4-设置输入参数IVariantArray parameters = new VarArrayClass();parameters.Add(@"F:\lib_test\地下水重金属数据.xls\Sheet1$");parameters.Add("`YEAR` = 2009");parameters.Add("W20111");parameters.Add(@"F:\lib_test\temp.gdb\tempwww");//5-执行工具gp.Execute("ModelAnalysis", parameters, null);
ESRI官方帮助示例:
1.
using ESRI.ArcGIS.Geoprocessor; using ESRI.ArcGIS.AnalysisTools;public void SampleBufferTool() {// Initialize the geoprocessor. Geoprocessor GP = new Geoprocessor();ESRI.ArcGIS.AnalysisTools.Buffer bufferTool = newESRI.ArcGIS.AnalysisTools.Buffer();bufferTool.in_features = @"D:\St_Johns\data.mdb\roads_Buffer";bufferTool.out_feature_class = @"D:\St_Johns\data.mdb\roads";bufferTool.buffer_distance_or_field = "distance";GP.Execute(bufferTool, null);}
2.
using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.esriSystem;public void SampleCalculateBestPathTool()
{// Initialize the geoprocessor.Geoprocessor GP = new Geoprocessor();// Add the BestPath toolbox.GP.AddToolbox(@"C:\SanDiego\BestPath.tbx");// Generate the array of parameters.IVariantArray parameters = new VarArrayClass();parameters.Add(@"C:\SanDiego\source.shp");parameters.Add(@"C:\SanDiego\destination.shp");parameters.Add(@"C:\SanDiego\bestpath.shp");// Execute the model tool by name.GP.Execute("CalculateBestPath", parameters, null);
转自http://blog.csdn.net/lysc_forever/article/details/7674332
这篇关于AE调用GP的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!