//引入命名空间
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geoprocessor;
//创建执行GP工具通用类
protected void ExecuteGPTool(IGPProcess gpProcess, Geoprocessor gp = null)
{
if (gp == null)
{
gp = new Geoprocessor();
gp.OverwriteOutput = true;
gp.LogHistory = true;
}
gp.ClearMessages();
try
{
gp.Execute(gpProcess, null);
}
catch (Exception)
{
object sev = null;
MessageBox.Show(gp.GetMessages(ref sev));
}
finally
{
}
}
//调用事例代码
//分析工具-提取分析-筛选
ESRI.ArcGIS.AnalysisTools.Select pSelect = new ESRI.ArcGIS.AnalysisTools.Select();
pSelect.in_features =inFeatureClass;//这里也可以传图层路径
pSelect.out_feature_class =outFeatureClass;//这里也可以传图层路径
pSelect.where_clause = "OBJNAME='aa'";
ExecuteGPTool(pSelect);
//调用字段计算器计算椭球面积
ESRI.ArcGIS.DataManagementTools.CalculateField pCalc = new ESRI.ArcGIS.DataManagementTools.CalculateField();
pCalc.in_table = featureClass;
pCalc.field = "MJ1";
pCalc.expression = "!shape.geodesicarea!";
pCalc.expression_type = "PYTHON";
ExecuteGPTool(pCalc);