zoukankan      html  css  js  c++  java
  • C#AE调用GP工具生成TIN三角网

    未有特别说明均为原创,转载注明出处。

     网上面这方面资料比较少,ArcGIS官方网站只给了python如何生成Tin,其实可以对比python写法,写出C#版本代码。

    以下是具体代码

    public static void generateTIN_Advance() 
    {
        Stopwatch sw = new Stopwatch();
        sw.Start();
        try
        {
            ILayer pLayer = Property.axMapControl.get_Layer(0);//随便打开生成TIN数据的原文件
            IFeatureLayer pFeaLayer = pLayer as IFeatureLayer;
            string strFeaLayerPath = encryptionAlgorithm.getLayerStorePath(pFeaLayer);
            IWorkspaceFactory pwf = new ShapefileWorkspaceFactory();
            IFeatureWorkspace pfw = pwf.OpenFromFile(strFeaLayerPath, 0) as IFeatureWorkspace;
            IFeatureClass pfc1 = pfw.OpenFeatureClass("XXX.shp");
            IFeatureClass pfc2 = pfw.OpenFeatureClass("XXX2.shp");
            Geoprocessor GP = new Geoprocessor();
            CreateTin createTin = new CreateTin();
            string strCreateTinName = "Tin";         
            if (Directory.Exists(strFeaLayerPath + @"" + strCreateTinName))//如果已经存在 删除已经存在的TIN 
            {
                Directory.Delete(strFeaLayerPath + @"" + strCreateTinName, true);
            }
            else////创建存放TIN的文件夹     
            {
                string parentPath = Directory.GetParent(strFeaLayerPath + @"" + strCreateTinName).FullName;
                if (!Directory.Exists(parentPath))
                {
                    Directory.CreateDirectory(parentPath);
                }
            }     
            //设置输入文件参数
            string height_field = "Shape.Z";
            string SF_type1 = "Mass_Points";//"masspoints"
            string SF_type2 ="Hard_Clip";// "hardclip"
            string tag_value = "<None>";//"" "null"
            //生成GP属性表格对象
            GpValueTableObject gpValueTableObject = new GpValueTableObjectClass();
            //文件obj1 参数设置
            object obj11 = pfc1;//strFeaLayerPath + @"" + pfc1.AliasName + ".shp ";
            object obj12 = height_field;
            object obj13 = SF_type1;
            object obj14 = tag_value;
            //文件obj2 参数设置
            object obj21 = pfc2;//strFeaLayerPath + @"" + pfc2.AliasName + ".shp ";
            object obj22 = height_field;
            object obj23 = SF_type2;
            object obj24 = tag_value;
            //设置GP属性表列数
            gpValueTableObject.SetColumns(4);
            //设置GP属性表行数 同时传入文件
            gpValueTableObject.AddRow(ref obj11);
            gpValueTableObject.AddRow(ref obj21);
            //向GP属性表内填入参数 注意已经设置过每行的第0列 即上步骤中传入的文件
            //gpValueTableObject.SetValue(0, 0, obj11);
            gpValueTableObject.SetValue(0, 1, obj12);
            gpValueTableObject.SetValue(0, 2, obj13);
            gpValueTableObject.SetValue(0, 3, obj14);
            //gpValueTableObject.SetValue(1, 0, obj21);
            //gpValueTableObject.SetValue(1, 1, obj22);
            gpValueTableObject.SetValue(1, 2, obj23);
            gpValueTableObject.SetValue(1, 3, obj24);
            //调用 实例化TIN接口,输入要素为GP属性表,输出要素路径和文件名
            string outTin = strFeaLayerPath + @"" + strCreateTinName;
            //gp.Execute("CreateTin_3d", parameters, null);
            createTin.in_features = gpValueTableObject;
            createTin.out_tin = outTin;
            //执行GP工具,将creatTin放入
            GP.Execute(createTin, null);
            // Wait until the execution completes.
            // while (result.Status == esriJobStatus.esriJobExecuting)
            //     Thread.Sleep(1000);
            // // Wait for 1 second.
            //MessageBox.Show(gp.GetMessages(ref sev));
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
        sw.Stop();
        TimeSpan ts2 = sw.Elapsed;
        MessageBox.Show(String.Format("Stopwatch总共花费{0}ms.
    即{1}s.
    即{2}min", Convert.ToString(ts2.TotalMilliseconds), Convert.ToString(ts2.TotalMilliseconds / 1000), Convert.ToString(ts2.TotalMilliseconds / 1000 / 60)));      
    }

  • 相关阅读:
    【Python】【文件】查找指定路径中是否存在目标文件(含此路径下的子文件夹)
    时隔一年的2020noip
    nacos 笔记
    webflux 小例子
    spring Initializr 笔记
    临时~spring启动过程
    Mac通过crontab设置定时任务报错Operation not permitted
    Isolation Forest Implementation(孤立森林)
    let arr=['a'] JSON.stringify(arr) 输出:“['a']” let arr2 = “['a']” JSON.parse(arr2) 输出: ['a']
    js对象中key值加引号和不加引号的区别
  • 原文地址:https://www.cnblogs.com/marvelousone/p/10747342.html
Copyright © 2011-2022 走看看