GP处理栅格数据

最近在做二次开发,遇到矢量图层和栅格图层叠加运算 ,用多边形裁切栅格影像的问题 一直没有解决, 花好久时间在这上面, 想尽思路寻找矢量和栅格叠加运算, 来解决问题,可问题依然在,要不就是遍历栅格影像来获取结果,运算时间慢不说且耗用内存,遇到大点的影像就要分割来算,解决下了要上千行码。。。。。

逛论坛看到有人说用Geoprocessor来解决,才知道可以运用ArcGIS ArcToolBox中的工具直接运算,简单明了,见识短浅啊~

进入正题,AE中调用Geoprocessor(下面称为GP),添加几个引用以及ArcToolBoxes里面的引用

using esri.arcgis.esrisystem

using esri.arcgis.geoprocessor

using esri.arcgis.geoprocessing

using esri.arcgis.spatialanalysttool(路径ArcGIS安装目录下\DotNet\Toolboxes)

主要就是这几个引用吧,然后就可以new 了,原本以为就可以用了,可是尝试几次结果总是为空,不过通过以下代码,找出原因:the tool is not licensed.

又查找资料解决license问题,ArcGIS Engine开发,许可问题,accessing licensing and extensions for the geoprocessor,又参考以下内容才解决,其中涉及到的esri.arcgis.version.dll问题,貌似在10.0以后才有,9.X都没有。

<span style="font-size: 18px;"><span style="font-size: 14px;"></span>
</span>

具体调用GP过程,请参照

[csharp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <span style="font-size:18px;">//添加命名空间  
  2.  using ESRI.ArcGIS.esriSystem;  
  3.  using ESRI.ArcGIS.Geoprocessor;  
  4.    
  5. //实现button click方法  
  6.  private void button1_Click(object sender, EventArgs e)  
  7.  {  
  8.  //构造Geoprocessor  
  9.  Geoprocessor gp = new Geoprocessor();  
  10.  //设置参数  
  11.  ESRI.ArcGIS.AnalysisTools.Intersect intersect = new ESRI.ArcGIS.AnalysisTools.Intersect();  
  12.  intersect.in_features = @"F:\foshan\Data\wuqutu_b.shp;F:\foshan\Data\world30.shp";  
  13.  intersect.out_feature_class = @"E:\intersect.shp";  
  14.  intersect.join_attributes = "ONLY_FID";  
  15.  //执行Intersect工具  
  16.  RunTool(gp, intersect, null);  
  17.  }  
  18.    
  19. private void RunTool(Geoprocessor geoprocessor, IGPProcess process, ITrackCancel TC)  
  20.  {  
  21.  // Set the overwrite output option to true  
  22.  geoprocessor.OverwriteOutput = true;  
  23.    
  24. try  
  25.  {  
  26.  geoprocessor.Execute(process, null);  
  27.  ReturnMessages(geoprocessor);  
  28.    
  29. }  
  30.  catch (Exception err)  
  31.  {  
  32.  Console.WriteLine(err.Message);  
  33.  ReturnMessages(geoprocessor);  
  34.  }  
  35.  }  
  36.    
  37. // Function for returning the tool messages.  
  38.  private void ReturnMessages(Geoprocessor gp)  
  39.  {  
  40.  string ms = "";  
  41.  if (gp.MessageCount > 0)  
  42.  {  
  43.  for (int Count = 0; Count <= gp.MessageCount - 1; Count++)  
  44.  {  
  45.  ms += gp.GetMessage(Count);  
  46.  }  
  47.  }</span>  
以上代码参考: http://www.xuebuyuan.com/1397721.html


许可问题,请参考:

<span style="font-size: 24px;"><span style="font-size: 18px;"><span class="kwrd">static</span> <span class="kwrd">void</span> Main(<span class="kwrd">string</span>[] args)
{
    <span class="rem">// Add runtime management  </span>
    ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);(9.3中我注释掉了,因为找不到RuntimeManager,而它在命名空间esri.arcgis.version中))

    <span class="rem">//Initialize the application.</span>
    esriLicenseStatus licenseStatus = esriLicenseStatus.esriLicenseUnavailable;
    IAoInitialize m_AoInitialize = <span class="kwrd">new</span> AoInitializeClass();
    licenseStatus = m_AoInitialize.Initialize
        (esriLicenseProductCode.esriLicenseProductCodeArcInfo);
    licenseStatus = m_AoInitialize.CheckOutExtension
        (esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst);

    <span class="rem">// Initialize the geoprocessor.         </span>
    Geoprocessor gp = <span class="kwrd">new</span> Geoprocessor();
    Slope tSlope = <span class="kwrd">new</span> Slope();
    tSlope.in_raster = <span class="str">@"E:\Data\demlatgrd"</span>;
    tSlope.out_raster = <span class="str">@"E:\Data\aspect03"</span>;
    gp.Execute(tSlope, <span class="kwrd">null</span>);

    licenseStatus = m_AoInitialize.CheckInExtension
        (esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst);
    m_AoInitialize.Shutdown();
    m_AoInitialize = <span class="kwrd">null</span>;

}
来自:<span style="font-size: 14px;">http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Accessing_licensing_and_extensions_for_the_geoprocessor/00010000024v000000/</span></span></span>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值