AE调用GP

借用别人的东西,将这两种方法放在一起:

第一种,分别设置参数:


 

//添加命名空间
 using ESRI.ArcGIS.esriSystem;
 using ESRI.ArcGIS.Geoprocessor;
 
//实现button click方法
 private void button1_Click(object sender, EventArgs e)
 {
 //构造Geoprocessor
 Geoprocessor gp = new 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);
 }
 }
 


另一种添加参数:

//1-定义GeoProcessor对象
 Geoprocessor gp = new Geoprocessor();
 object sev = null;
 //2-设置参数
 gp.OverwriteOutput = true;
 //3-设置工具箱所在的路径
 gp.AddToolbox(@"F:\lib_test\AirportsAndGolf.tbx");
 //4-设置输入参数
 IVariantArray parameters = new VarArrayClass();
 parameters.Add(@"F:\lib_test\地下水重金属数据.xls\Sheet1$");
 parameters.Add("`YEAR` = 2009");
 parameters.Add("W20111");
 parameters.Add(@"F:\lib_test\temp.gdb\tempwww");
 
//5-执行工具
 gp.Execute("ModelAnalysis", parameters, null);


 

ESRI官方帮助示例:

1.

using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.AnalysisTools;

public void SampleBufferTool()
{

  // Initialize the geoprocessor. 
  Geoprocessor GP = new Geoprocessor();

  ESRI.ArcGIS.AnalysisTools.Buffer bufferTool = new
    ESRI.ArcGIS.AnalysisTools.Buffer();

  bufferTool.in_features = @"D:\St_Johns\data.mdb\roads_Buffer";
  bufferTool.out_feature_class = @"D:\St_Johns\data.mdb\roads";
  bufferTool.buffer_distance_or_field = "distance";

  GP.Execute(bufferTool, null);

}

2.

using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.esriSystem;

public void SampleCalculateBestPathTool()
{

  // Initialize the geoprocessor.
  Geoprocessor GP = new Geoprocessor();

  // Add the BestPath toolbox.
  GP.AddToolbox(@"C:\SanDiego\BestPath.tbx");

  // Generate the array of parameters.
  IVariantArray parameters = new VarArrayClass();
  parameters.Add(@"C:\SanDiego\source.shp");
  parameters.Add(@"C:\SanDiego\destination.shp");
  parameters.Add(@"C:\SanDiego\bestpath.shp");

  // Execute the model tool by name.
  GP.Execute("CalculateBestPath", parameters, null);
转自http://blog.csdn.net/lysc_forever/article/details/7674332

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,我们可以了解到OPC是一种利用微软的COM/DCOM技术来达成自动化控制的协定,而OPC AE是OPC中的一种规范,用于实现事件驱动的自动化控制。下面是C#调用OPC AE的步骤: 1.安装OPC AE服务器和客户端组件,例如KepServer等。 2.在C#项目中添加对OPC AE客户端组件的引用。 3.创建OPC AE客户端对象并连接到OPC AE服务器。 ```csharp using OPCDA.NET; OPCServer opcServer = new OPCServer(); opcServer.Connect("Kepware.KEPServerEX.V6", ""); ``` 4.获取OPC AE服务器中的事件项列表。 ```csharp OPCGroup opcGroup = opcServer.OPCGroups.Add("Group1"); OPCItems opcItems = opcGroup.OPCItems; OPCEventServer opcEventServer = opcServer.OPCEventServer; OPCEventSubscription opcEventSubscription = opcEventServer.CreateSubscription(); OPCEventArea opcEventArea = opcEventSubscription.OPCEventAreas.Add("Area1"); OPCEventCategory opcEventCategory = opcEventArea.OPCEventCategories.Add("Category1"); OPCEvent opcEvent = opcEventCategory.OPCEvents.Add("Event1"); OPCEventCondition opcEventCondition = opcEvent.OPCEventConditions.Add("Condition1"); OPCEventAttribute opcEventAttribute = opcEventCondition.OPCEventAttributes.Add("Attribute1"); OPCEventItem opcEventItem = opcItems.AddItem("Item1", 1); opcEventAttribute.OPCEventItem = opcEventItem; ``` 5.注册OPC AE事件处理程序。 ```csharp public void OnEvent(object sender, OPCEventArguments e) { Console.WriteLine("Event received: {0}", e.Message); } opcEventSubscription.DataChanged += new OPCEventServer.DataChangeEventHandler(OnEvent); ``` 6.启动OPC AE事件订阅。 ```csharp opcEventSubscription.Active = true; ``` 7.等待OPC AE事件的发生。 ```csharp while (true) { System.Threading.Thread.Sleep(1000); } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值