AE 调用 GP 以及调用过程中产生的若干问题

来源:互联网 发布:怎么做推文用什么软件 编辑:程序博客网 时间:2024/06/07 01:42

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

逛论坛看到有人说用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都没有。

具体调用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); } }
以上代码参考:http://www.xuebuyuan.com/1397721.html


许可问题,请参考:

static void Main(string[] args){    // Add runtime management      ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);(9.3中我注释掉了,因为找不到RuntimeManager,而它在命名空间esri.arcgis.version中))    //Initialize the application.    esriLicenseStatus licenseStatus = esriLicenseStatus.esriLicenseUnavailable;    IAoInitialize m_AoInitialize = new AoInitializeClass();    licenseStatus = m_AoInitialize.Initialize        (esriLicenseProductCode.esriLicenseProductCodeArcInfo);    licenseStatus = m_AoInitialize.CheckOutExtension        (esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst);    // Initialize the geoprocessor.             Geoprocessor gp = new Geoprocessor();    Slope tSlope = new Slope();    tSlope.in_raster = @"E:\Data\demlatgrd";    tSlope.out_raster = @"E:\Data\aspect03";    gp.Execute(tSlope, null);    licenseStatus = m_AoInitialize.CheckInExtension        (esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst);    m_AoInitialize.Shutdown();    m_AoInitialize = null;}来自:http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Accessing_licensing_and_extensions_for_the_geoprocessor/00010000024v000000/




0 0