AE调用gp服务

参考:http://www.cnblogs.com/zhangjun1130/archive/2010/05/26/1744472.html

     Geoprocessing是ArcGIS提供的一个非常实用的工具,借由Geoprocessing工具可以方便的调用ArcToolBox中提供的各类工具,本文在ArcEngine9.2平台环境下总结了调用ArcToolBox工具的使用方法:

        1、调用ArcToolBox工具方法

         以ArcToolBox->Analysis Tools->Proximity->Buffer工具的调用为例,C#代码如下:

         using ESRI.ArcGIS.AnalysisTools;         //添加引用
         using ESRI.ArcGIS.Geoprocessor;

         Geoprocessor gp = new Geoprocessor();    //初始化Geoprocessor
         gp.OverwriteOutput = true;                     //允许运算结果覆盖现有文件

         ESRI.ArcGIS.AnalysisTools.Buffer pBuffer = new ESRI.ArcGIS.AnalysisTools.Buffer(); //定义Buffer工具
         pBuffer.in_features = pVorLineLayer;    //输入对象,既可是IFeatureLayer对象,也可是完整文件路径如“D:\\data.shp”
         pBuffer.out_feature_class = pBuffer;     //输出对象,一般是包含输出文件名的完整文件路径,如“D:\\buffer.shp”

         //设置缓冲区的大小,即可是带单位的具体数值,如0.1 Decimal Degrees;也可是输入图层中的某个字段,如“BufferLeng”
         pBuffer.buffer_distance_or_field = "BufferLeng";    
         pBuffer.dissolve_option = "ALL";     //支持融合缓冲区重叠交叉部分
         gp.Execute(pBuffer, null);                //执行缓冲区分析

  2、参数设置

        在调用ArcToolBox执行具体的分析操作时,需要设置各类输入输出参数,简单概括起来说主要分为两类:对应于Environment Settings对话框的Geoprocessor对象设置、对应于具体操作窗口的方法设置。以ArcToolBox->Analysis Tools->Overlay->Intersect为例,C#代码如下:

            Geoprocessor gp = new Geoprocessor();
            gp.OverwriteOutput = true;    //覆盖原有文件并重写

            //Environment Settings对话框参数设置,具体名称参考操作界面Help中对应参数文档 

            object obj = gp.GetEnvironmentValue("Extent");  //设置Exten,大小写无关;          

            gp.SetEnvironmentValue("Extent", "MAXOF");     //或者"113.697050 115.074770 29.969986 31.362495"

            obj = gp.GetEnvironmentValue("OutputZFlag");                    //设置Output has Z Values
            gp.SetEnvironmentValue("OutputZFlag", "DEFAULT");

            obj = gp.GetEnvironmentValue("OutputMFlag");                    //设置Output has M Values
            gp.SetEnvironmentValue("OutputMFlag", "DEFAULT");

            obj = gp.GetEnvironmentValue("OutputCoordinateSystem");  //设置Output Coordinate System
            gp.SetEnvironmentValue("OutputCoordinateSystem", Application.StartupPath + "\\zhouyang.prj");

            obj = gp.GetEnvironmentValue("QualifiedFieldNames");         //设置Maintain fully qualifid field names
            gp.SetEnvironmentValue("QualifiedFieldNames", "QUALIFIED");

//具体操作窗口的方法设置

            Intersect pIntersect = new Intersect();
            //多个对象的输入:用分号隔开包含完整路径的文件名
            pIntersect.in_features = pInputFeature1 + ";" + pInputFeature2;

     //多个对象的输入:使用IGpValueTableObject接口,该接口可以设置Rank(http://resources.esri.com/help/9.3/arcgisengine/dotnet/84349562-e062-44ee-8db0-9fcdcd64708b.htm

     //object inputfeature1 = @"D:\周杨\贝贝\WuhanCity\ThiessenPolygons_Line_Buffer.shp";
            //object inputfeature2 = @"D:\周杨\贝贝\wuhanCity_shp\poi Point.shp";
            //IGpValueTableObject pObject = new GpValueTableObjectClass();
            //pObject.SetColumns(2);
            //pObject.AddRow(ref inputfeature1);
            //pObject.AddRow(ref inputfeature2);
            //pIntersect.in_features = pObject;
            pIntersect.out_feature_class = pOutputFeature;
            pIntersect.join_attributes = "All";
            pIntersect.output_type = "POINT";

     gp.Execute(pIntersect, null);      //执行

 

  3、运行结果对象提取

  Geoprocessor对象通过Execute方法执行后将结果保存到指定输出路径下,通过也可以通过IGeoProcessorResult接口读取存储在内容中的结果对象,C#代码如下:

    //执行图层求交运算
            IGeoProcessorResult pResult = (IGeoProcessorResult)gp.Execute(pIntersect, null);

     IGPUtilities pGPUtil = new GPUtilitiesClass();
            IFeatureClass pFC;
            IQueryFilter pQF;
            pGPUtil.DecodeFeatureLayer(pResult.GetOutput(0),out pFC,out pQF);
            int count = pFC.FeatureCount(null);      //统计Feature对象个数
            IFeatureCursor pCursor = pFC.Insert(true);   //提取FeatureCursor对象
            IFeatureLayer pFeatureLayer = new FeatureLayerClass();
            pFeatureLayer.FeatureClass = pFC;
            m_mapControl.Map.AddLayer(pFeatureLayer);   //加载图层对象

 

 

运行自定义的geoprocessing工具

  除了使用现有的工具和ESRI提供的工具箱,也可以执行你自定义的工具,比如model tools(模型工具)和script tools(脚本工具),他们存在于自定义工具箱中。使用集成开发环境(IDE)框架嵌入在Visual Studio .NET中,你可以生成geoprocessing程序集用来重现任何自定义工具箱。这样做,使用ArcGIS Toolbox Reference对话框。


引用名称执行工具

  声明你的自定义工具箱并不是生成geoprocessing程序集的先决条件。这里有另外一种使用geoprocessor的方式来使用Execute方法。Execute方法已经被重载和附加,允许您通过指定工具的名称、工具的参数和ITrackCancel接口来执行工具。

  下面是一个执行计算最优路径模型的工具,它位于BestPath工具箱中:

    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);  
    }  

执行geoprocessing server工具

  通过ArcGIS Desktop和ArcGIS Engine(9.2及以上版本),你可以执行发布在ArcGIS Server上的geoprocessing工具。Server工具能通过像自定义工具一样执行。首先你必须添加工具箱,这个工具箱是生成一个geoprocessing toolbox assembly来表示或使用AddToolbox方法添加自定义的。

  工具箱能够发布在局域网(LAN)或者作为一个Web服务发布在Internet上。要想使用geoprocessing服务工具,你必须添加工具箱。下面的示例代码显示了如何使用AddToolbox方法添加发布在ArcGIS Server的工具。

 

using ESRI.ArcGIS.Geoprocessor;  
  
public void SampleGeoprocessingServerTool(Geoprocessor GP)  
{  
  
  // Add the BestPath toolbox published on a LAN.  
  // Entered as server name;folder/toolbox.  
  GP.AddToolbox(@"flame7;SanDiego/BestPath");  
  
  // Add the BestPath toolbox published as a geoprocessing Web service.  
  // Entered as Web service;folder/toolbox.  
  GP.AddToolbox(@"http://flame7/arcgis/services;SanDiego/BestPath");  
  
  //TODO: Add your code here...  
  

 

其中在arccatalog中添加GIS Server时 host Name同 arcgis server manager 打开时的网址中的内容如:

则添加工具代码为:

GP.AddToolbox(@"http://192.168.0.200:8399/arcgis/services;tt/tbx");


如果无端口号信息则:

则添加工具代码为:
GP.AddToolbox(@"http://temp-pc/arcgis/services;tt/tbx");
 
  

 

 

 

转载于:https://www.cnblogs.com/nygfcn1234/p/3628252.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值