执行模型工具箱


///


/// 执行模型工具
///

/// 工具箱路径
/// 模型名称
/// 模型参数集合
/// 输出覆盖,true为覆盖,false为不覆盖
///
public static bool ExecuteModel(string toolBoxPath, string modelName, IVariantArray parameters, bool overwrite)
{
object sev = null;//用来标记处理信息
//1-定义GeoProcessor对象
// Geoprocessor gp = new Geoprocessor();
IGeoProcessor2 gp = new GeoProcessorClass();
//2-设置参数
gp.OverwriteOutput = overwrite;
//3-设置工具箱所在的路径
gp.AddToolbox(toolBoxPath);

//5-执行工具
try
{
gp.Execute(modelName, parameters, null);
return true;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///


/// 执行模型工具
///

/// 工具箱路径
/// 模型名称
/// 模型参数集合
///
public static bool ExecuteModel(string toolBoxPath, string modelName, IVariantArray parameters)
{
//1-定义GeoProcessor对象
// Geoprocessor gp = new Geoprocessor();
IGeoProcessor2 gp = new GeoProcessorClass();
//2-设置参数
gp.OverwriteOutput = true;
//3-设置工具箱所在的路径
gp.AddToolbox(toolBoxPath);

//5-执行工具
try
{
gp.Execute(modelName, parameters, null);
return true;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}

public static bool ExecuteModel(string toolBoxPath, string modelName, List parameters)
{
//1-定义GeoProcessor对象
// Geoprocessor gp = new Geoprocessor();
IGeoProcessor2 gp = new GeoProcessorClass();
//2-设置参数
gp.OverwriteOutput = true;
//3-设置工具箱所在的路径
gp.AddToolbox(toolBoxPath);

//5-执行工具
try
{
gp.Execute(modelName, listToArray(parameters), null);
return true;
}
catch (Exception ex)
{
return false;
}
}