ESRI.ArcGIS.AnalysisTools 与 ESRI.ArcGIS.Geoprocessor

来源:互联网 发布:sqlserver 商业智能 编辑:程序博客网 时间:2024/06/11 18:47
使用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中的很多功能无法使用,所以要重新设置。注意:在axLicenseControl上进行右键查属性设置无法使设置生效,故只能加代码。



ArcGIS Engine中调用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); } } 

//1-定义GeoProcessor对象 Geoprocessor gp = new Geoprocessor(); object sev = null; //2-设置参数 gp.OverwriteOutput = true; //3-设置工具箱所在的路径 gp.AddToolbox(@"F:\lib_test\AirportsAndGolf.tbx"); //4-设置输入参数 IVariantArray parameters = new VarArrayClass(); parameters.Add(@"F:\lib_test\地下水重金属数据.xls\Sheet1$"); parameters.Add("`YEAR` = 2009"); parameters.Add("W20111"); parameters.Add(@"F:\lib_test\temp.gdb\tempwww"); //5-执行工具 gp.Execute("ModelAnalysis", parameters, null);


ESRI官方帮助示例:

using ESRI.ArcGIS.Geoprocessor;using ESRI.ArcGIS.AnalysisTools;public void SampleBufferTool(){  // Initialize the geoprocessor.   Geoprocessor GP = new Geoprocessor();  ESRI.ArcGIS.AnalysisTools.Buffer bufferTool = new    ESRI.ArcGIS.AnalysisTools.Buffer();  bufferTool.in_features = @"D:\St_Johns\data.mdb\roads_Buffer";  bufferTool.out_feature_class = @"D:\St_Johns\data.mdb\roads";  bufferTool.buffer_distance_or_field = "distance";  GP.Execute(bufferTool, null);}

using ESRI.ArcGIS.Geoprocessor;using ESRI.ArcGIS.esriSystem;public void SampleCalculateBestPathTool(){  // Initialize the geoprocessor.  Geoprocessor GP = new Geoprocessor();  // Add the BestPath toolbox.  GP.AddToolbox(@"C:\SanDiego\BestPath.tbx");  // Generate the array of parameters.  IVariantArray parameters = new VarArrayClass();  parameters.Add(@"C:\SanDiego\source.shp");  parameters.Add(@"C:\SanDiego\destination.shp");  parameters.Add(@"C:\SanDiego\bestpath.shp");  // Execute the model tool by name.  GP.Execute("CalculateBestPath", parameters, null);



0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 天猫店手机发货成定制机怎么办 天猫退货上门取件退两件怎么办 买二手苹果手机没有账号怎么办 手机淘宝足迹不更新怎么办 淘宝申请退款不想退了怎么办 荣耀3c主板坏了怎么办 荣耀10天气删了怎么办 荣耀7i手机卡顿怎么办 荣耀v9总是自己拨号怎么办 华为荣耀5x很卡怎么办 华为荣耀6plus卡怎么办 华为手机触屏不灵敏怎么办 华为荣耀6x太卡怎么办 华为荣耀7太卡怎么办 荣耀手机开不开机怎么办 华为g750手机开不了机怎么办 华为手机开不了机怎么办 小米手机刷机后激活不了帐号怎么办 魅蓝note5卡顿怎么办 魅蓝note5卡了怎么办 魅蓝note5很卡怎么办 魅蓝note5锁了怎么办 荣耀9开不开机怎么办 4s更新后用不了怎么办 魅蓝3开不了机怎么办 手机不支持联通4g网络怎么办 华为手机出现emui界面怎么办 华为畅玩4x内存不足怎么办 手机电源键掉了怎么办 手机电源键坏了怎么办 小米5s听筒声音小怎么办 荣耀8电源键失灵怎么办 华为荣耀3c卡怎么办 大王卡是2g网络怎么办 联通停用2g副卡怎么办 华为荣耀8忘记解锁密码怎么办 华为手机内存满了怎么办 华为手机无限重启怎么办 华为3c重启怎么办 荣耀6 无限重启怎么办 手机进水无法开机了怎么办