arcgis 二次开发之工具箱和工具调用
///
/// 执行GP工具
///
/// GP对象
/// 使用工具
///
/// 成功返回true/失败返回false
public static bool RunTool(Geoprocessor geoprocessor, IGPProcess process, ITrackCancel
TC)
{
geoprocessor.OverwriteOutput = true;//存在覆盖
try
{
IGeoProcessorResult result =
(IGeoProcessorResult)geoprocessor.Execute(process, null);//取执行结果
if (result != null)
{
if (result.Status == esriJobStatus.esriJobSucceeded) //执行成功
{
return true;
}
} if (geoprocessor.MessageCount > 0) //失败显示错误原因
{
for (int i = 0; i < geoprocessor.MessageCount; i++)
{
MessageBox.Show(geoprocessor.GetMessage(i));
}
return false;
}
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
return false;
}
public static bool Dissolve(string inFeaturesPath, string outFeaturePath, string dissolveFieldName)
{
Geoprocessor GP = new Geoprocessor();
ESRI.ArcGIS.DataManagementTools.Dissolve dissolve = new
ESRI.ArcGIS.DataManagementTools.Dissolve();
dissolve.in_features = inFeaturesPath;
dissolve.out_feature_class = outFeaturePath;
dissolve.dissolve_field = dissolveFieldName;
dissolve.multi_part = “false”;
return RunTool(GP, dissolve, null);
}