最近在做二次开发,遇到矢量图层和栅格图层叠加运算 ,用多边形裁切栅格影像的问题 一直没有解决, 花好久时间在这上面, 想尽思路寻找矢量和栅格叠加运算, 来解决问题,可问题依然在,要不就是遍历栅格影像来获取结果,运算时间慢不说且耗用内存,遇到大点的影像就要分割来算,解决下了要上千行码。。。。。
逛论坛看到有人说用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过程,请参照
- <span style="font-size:18px;">//添加命名空间
- 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);
- }
- }</span>
许可问题,请参考:
<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>