geoprocessor test (转载——待测)
geoprocessing唯一难的地方就是参数,需要根据不同的情况设置,
我就以intersect方法为例,编程实现两个图层的intersect.
新建一个项目,添加引用,我们用的工具intersect是在AnalysisTools中的,在form中加一个button,然后实现其方法,如下,
别忘了添加命名空间
using System; using System.Collections.Generic; using System.Linq; using System.Text; using ESRI.ArcGIS.ArcMap; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Geoprocessor; namespace LandEnvaluation { class gptest { //实现button click方法 private void button1_Click(object sender, EventArgs e) { //构造Geoprocessor ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.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 true geoprocessor.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); } } } } }