用心计较般般错 安心自守事事宽

cgl 坚持、努力终有所获
  新随笔  :: 管理

ArcEngine10.2开发,ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);代码加入后,就无需axLicenseControl控件添加到项目中(注意:如果要用到扩展lic,那么需要额外添加AoInitialize.CheckOutExtension方法)

GP对ESRI.ArcGIS.AnalysisTools.Select 。Select需要的Lic 的Level为

情况:

ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);

输入参数和输出参数不涉及到sde数据库,执行成功。如果涉及到sde数据库,执行错误,错误消息:

M:对 COM 组件的调用返回了错误 HRESULT E_FAIL。

C:-2147467259

如果要执行成功,需要修改:

ESRI.ArcGIS.RuntimeManager.BindLicense(ESRI.ArcGIS.ProductCode.EngineOrDesktop,ESRI.ArcGIS.LicenseLevel.GeodatabaseUpdate);

如果输入、输出的参数填写错误,错误消息与上述相同。

M:对 COM 组件的调用返回了错误 HRESULT E_FAIL。

C:-2147467259

 

备注:在添加:axLicenseControl控件,ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop) 的情况下,如果以

m_geoprocessor.ExecuteAsync 异步的情况下执行,也可以成功。相当奇怪。

总结:
(1)如果不涉及sde数据库,那么ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop) 加m_geoprocessor.Execute同步的情况下,执行成功。
(2)如果涉及到sde数据库,那么ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop) 加axLicenseControl控件加m_geoprocessor.ExecuteAsync异步的情况下,执行成功
(3)如果涉及到sde数据库,那么ESRI.ArcGIS.RuntimeManager.BindLicense(ESRI.ArcGIS.ProductCode.EngineOrDesktop, ESRI.ArcGIS.LicenseLevel.GeodatabaseUpdate) 加_geoprocessor.Execute同步的情况下,执行成功。

对于错误消息的,一定要用下面的方法:
   m_geoprocessor.ToolExecuted += new EventHandler<ToolExecutedEventArgs>(_gp_ToolExecuted);
                    m_geoprocessor.ProgressChanged += new EventHandler<ESRI.ArcGIS.Geoprocessor.ProgressChangedEventArgs>(_gp_ProgressChanged);
                    m_geoprocessor.MessagesCreated += new EventHandler<MessagesCreatedEventArgs>(_gp_MessagesCreated);
                    m_geoprocessor.ToolExecuting += new EventHandler<ToolExecutingEventArgs>(_gp_ToolExecuting);

才能准确的知道,错误的原因。

例如错误消息中会有:

The application is not licensed to create or modify schema for this type of data 

能知道到底哪里出错了。

如果参数错误,会有以下消息:

Failed to execute. Parameters are not valid.

ERROR 000732: Input Features: Dataset E:\\SYS_POINTYC3 does not exist or is not supported

//////////////////////////////////////

同时,如果用下面的代码去执行GP,那么就无须添加对应的dll。即无需添加ESRI.ArcGIS.AnalysisTools

 

        public bool DrogLayerEx()
        {
            bool b = false;
            IGeoProcessor2 gp = new GeoProcessorClass();
            gp.OverwriteOutput = true;
            IGeoProcessorResult result = new GeoProcessorResultClass();
            IVariantArray parameters = new VarArrayClass();
            object sev = null;
            try
            {
                parameters.Add(_shpToOracleFile.oriFilePath);
                parameters.Add(_shpToOracleFile.tarFileName);
                parameters.Add(null);
                result = gp.Execute("Select_analysis", parameters, null);
                while (result.Status == esriJobStatus.esriJobExecuting)
                    Thread.Sleep(1000);
                Console.WriteLine(gp.GetMessages(ref sev));
                b = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(gp.GetMessages(ref sev));
            }
            return b;
        }

 执行一个简单的GP工具例子,参考:

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Accessing_licensing_and_extensions_for_the_geoprocessor/00010000024v000000/

static void Main(string[] args)
{
    // Add runtime management  
    ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);

    //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;

}