zoukankan      html  css  js  c++  java
  • 如何用ArcObjects SDK实现ArcTools中的create feature class功能

    https://www.cnblogs.com/2008nmj/p/13853911.html

    该gptool可以直接调用gp函数实现。

    那么,如何使用AE调用该gp函数呢?https://blog.csdn.net/xinying180/article/details/70158549?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.edu_weight&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.edu_weight

    一种是使用Geoprocessing类,工具参数使用IVariantArray方式输入;另一种是使用Geoprocessor托管类,创建工具对象,参数作为该工具对象的属性输入。下面就看下这两种调用方式的具体实现。

    一、使用GeoProcessing类

    主要分为以下几步:

    1.添加ESRI.ArcGIS.Geoprocessing引用,仅需要引用该类库

    2.创建geoprocessor对象,注意这里的P为大写

    3.如果调用自定义工具,需要添加自定义工具箱的路径

    4.创建IVariantArray对象,用于存放工具参数

    5.调用geoprocessor的Execute方法

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using ESRI.ArcGIS.Geoprocessing;
    using ESRI.ArcGIS.esriSystem;
    
    namespace gp_winform
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                IGeoProcessor2 gp = new GeoProcessorClass();
                //设置gp.OverwriteOutput是指可以用一个输出执行多次工具
                gp.OverwriteOutput = true;
                IGeoProcessorResult result = new GeoProcessorResultClass();
                //Create a variant array to hold the parameter values.
                IVariantArray parameters = new VarArrayClass();
                object sev = null;
                try
                {
                    //Populate the variant array with parameter values.
                    parameters.Add(FileGDBPath + "检查井");
                    parameters.Add(FileGDBPath + "检查井_buffer");
                    parameters.Add("100 Feet");
    
                    //Execute the tool
                    result = gp.Execute("Buffer_analysis", parameters, null);
                    //Print geoprocessing messages.
                    Console.WriteLine(gp.GetMessages(ref sev));
                }
                catch (Exception ex)
                {
                    //Print a generic exception message
                    Console.WriteLine(ex.Message);
                    //Print geoprocessing execution error messages
                    Console.WriteLine(gp.GetMessages(ref sev));
                }
            }
    
            public string FileGDBPath { get { return FileGDBPath;} set { FileGDBPath = @"C:UsersAdministratorDesktopeijingLightWeight.gdb"; } }
        }
    }

    二、使用GeoProcessor托管类

    主要分为以下几步:

    1. 添加ESRI.ArcGIS.Geoprocessor引用,如果想要获取执行结果result或者list datasets还需要引用ESRI.ArcGIS.Geoprocessing。

    2. 除此之外,需要添加该工具所在工具箱的引用。比如使用Buffer工具,则需要添加ESRI.ArcGIS.AnalysisTools引用,使用IDW工具,则需要添加ESRI.ArcGIS.SpatialAnalystTools引用,以此类推。

    3. 创建geoprocessor对象。

    4. 如果调用自定义工具,需要添加自定义工具箱的路径。

    5. 创建工具对象(tool process object)并且设置参数

    6. 调用geoprocessor的Execute方法。

    代码:

    //使用GeoProcessor托管类
    略
    略
    略
    略
    略
    略
    略
    略
    略
    略
    
    
    
    
    略
    
    略
    略略

    三、扩展:Create Feature Class

    》》Create Feature Class

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using ESRI.ArcGIS.Geoprocessing;
    using ESRI.ArcGIS.esriSystem;
    //using DinglerTools;
    
    namespace gp_winform
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)//Create Feature Class,两种方法,第一种调用GP工具就行了,第二种自行实现
            {
                string FileGDBPath = "C:\Users\Administrator\Desktop\beijingLightWeight.gdb\";
                string filename = "well1";
                IGeoProcessor2 gp = new GeoProcessorClass();
                //设置gp.OverwriteOutput是指可以用一个输出执行多次工具
                //gp.AddToolbox(@"C:UsersAdministratorDownloadsDinglerToolboxDinglerTools.tbx");
                gp.OverwriteOutput = true;
                IGeoProcessorResult result = new GeoProcessorResultClass();
                //Create a variant array to hold the parameter values.
                IVariantArray parameters = new VarArrayClass();
                object sev = null;
                try
                {
                    parameters.Add(FileGDBPath);//+ filename
                    parameters.Add(filename);
                    parameters.Add("POINT");
                    parameters.Add(FileGDBPath+"检查井");
                    //parameters.Add("100 Feet");
                    
                    
                    //Execute the tool
                    result = gp.Execute("CreateFeatureclass_management", parameters, null);
                    //Print geoprocessing messages.
                    Console.WriteLine(gp.GetMessages(ref sev));
                    MessageBox.Show("Well Done!
    "+gp.GetMessages(ref sev));
                }
                catch (Exception ex)
                {
                    //Print a generic exception message
                    Console.WriteLine(ex.Message);
                    MessageBox.Show(ex.Message);
                    //Print geoprocessing execution error messages
                    Console.WriteLine(gp.GetMessages(ref sev));
                    MessageBox.Show(gp.GetMessages(ref sev));
                }
            }
    
            
    
            private void Form1_Load(object sender, EventArgs e)
            {
                //ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engine);
            }
        }
    }

    >>特别注意:.net framework要选择2.0。。。然后选择arcgis desktop空项目即可。在前文https://www.cnblogs.com/2008nmj/p/13993479.html中所述的不适用于此功能。

  • 相关阅读:
    smtplib文字邮件的发送
    接口测试框架分析
    UnitTest框架的快速构建与运行
    Appium + Python App自动化第一个脚本
    3个必备cookie实用方法
    单元测试框架的选择
    快速构建一个完整的Selenium框架
    SSH原理与运用
    springboot 集成 spring-data-elasticsearch
    Java 集合排序
  • 原文地址:https://www.cnblogs.com/2008nmj/p/13998821.html
Copyright © 2011-2022 走看看