Arcengine中调用ArcToolbox工具(Geoprocessing)

来源:互联网 发布:专门画画的软件 编辑:程序博客网 时间:2024/05/16 16:16

geoprocessing唯一难的地方就是参数,需要根据不同的情况设置,
我就以intersect方法为例,编程实现两个图层的intersect.
新建一个项目,添加引用,我们用的工具intersect是在AnalysisTools中的,

 


在form中加一个button,然后实现其方法,如下,
别忘了添加命名空间
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geoprocessor;

//实现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);
}
}

}

原创粉丝点击