ESRI.ArcGIS.AnalysisTools的使用

本文解决了一个在使用ArcGIS Analysis Tools时遇到的许可问题,通过在主窗体初始化函数中加入代码,确保了工具的有效使用。重点介绍了如何在许可控制组件上设置正确的许可产品代码,以激活所需的功能。
这几天一直纠结一个问题,就是在AE下使用ESRI.ArcGIS.AnalysisTools中的工具(例如:泰森多边形的建立等)无法得到结果。例如使用以下代码:
        Geoprocessor gp = new Geoprocessor();
            gp.OverwriteOutput = true;

            ESRI.ArcGIS.AnalysisTools.CreateThiessenPolygons CTP = new CreateThiessenPolygons(@"D:\AEtestyao\Data\school.shp",
                                         "D:\AEtestyao\Data\CTP.shp");
            CTP.fields_to_copy = "ONLY_FID";          

            gp.Execute(CTP, null);

开始一直得不到结果,然后上网查了很久后终于解决了。一般都会是由于工具未注册导致(the tool is not licensed)。
解决方案为:在主窗体的初始化函数中加入代码,如下:
public Mainform()
        {
            #region 初始化许可
            IAoInitialize m_AoInitialize = new AoInitializeClass();
            esriLicenseStatus licenseStatus = esriLicenseStatus.esriLicenseUnavailable;
           
            licenseStatus = m_AoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcInfo);
            //默认第一个为有效地,之后无效,此级别最高,可用绝大多数功能

            //licenseStatus = m_AoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);级别最低

            #endregion

            InitializeComponent(); 
        }
关键代码一定要放正确,放到InitializeComponent()后会无效。
原因说明下:系统搭建时,axLicenseControl默认使用的是esriLicenseProductCodeEngine,这个的级别是最低的,导致ESRI.ArcGIS.AnalysisTools中的很多功能无法使用(而ESRI.ArcGIS.AnalysisTools得Buffer可用),所以要重新设置。注意:在axLicenseControl上进行右键查属性设置无法使设置生效,故只能加代码。
基于visual studio 2013实现缓冲区代码,对以下代码进行修改static string appPath = Environment.CurrentDirectory + "\\shp\\";//路径 默认存debug里 /// <summary> /// 单个缓冲区分析 /// </summary> /// <param name="mapControl">map控件</param> /// <param name="name">文件名</param> /// <param name="distances">缓冲半径</param> public static void Buffer(IMapControlDefault mapControl,string distances,string name) { string outPath = appPath+ ""+ name + distances + "_Buffer.shp"; IFeatureLayer featureLayer = getFeatureLayer(mapControl, "台风路径"); Geoprocessor gp = new Geoprocessor(); //初始化Geoprocessor gp.OverwriteOutput = true; //允许运算结果覆盖现有文件 try { ESRI.ArcGIS.AnalysisTools.Buffer pBuffer = new ESRI.ArcGIS.AnalysisTools.Buffer(); //定义Buffer工具 pBuffer.in_features = featureLayer; //输入对象,既可是IFeatureLayer对象,也可是完整文件路径如“D://data.shp” pBuffer.out_feature_class = outPath; //输出对象,一般是包含输出文件名的完整文件路径 //设置缓冲区的大小,即可是带单位的具体数值,如0.1 Decimal Degrees;也可是输入图层中的某个字段,如“BufferLeng” pBuffer.buffer_distance_or_field = "" + distances + " Kilometers"; //缓冲区参数 pBuffer.dissolve_option = "NONE"; //支持融合缓冲区重叠交叉部分 gp.Execute(pBuffer, null); //执行缓冲区分析 //添加结果到窗口 string pFolder = System.IO.Path.GetDirectoryName(outPath); //得到字符串中文件夹位置 string pFileName = System.IO.Path.GetFileName(outPath); //得到字符串中文件名字 mapControl.AddShapeFile(pFolder, pFileName); //往地图控件里添加文件 mapControl.ActiveView.Refresh(); //激活窗口刷新 } catch (Exception ex) { MessageBoxEX.Show("警告", "缓冲分析失败!" + ex.ToString()); } }
最新发布
06-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值