首页 > 代码库 > ArcEngine由点生成TIN

ArcEngine由点生成TIN

这两天替别人写一个三维校园的展示程序,用的是SceneControl二次开发。需要利用DOM和TIN构建三维地形。现在说下根据高程点生成TIN的过程:

(1)根据高程点文件(Excel)生成点shapefile

(2)使用ITinEdit的AddFromFeatureClass方法生成TIN

高程点数据格式如下:

操作界面如下:

生成TIN效果图:


代码很容易理解,如下:

   #region 创建TIN
        private void button_ok_Click(object sender , EventArgs e)
        {
            try
            {
                strTinName=textBox_TINName.Text;
                outFolder=textBox_outpath.Text;
                if (strTinName=="")
                {
                    MessageBox.Show("请输入TIN名称!");
                } 
                else if (outFolder=="")
                {
                    MessageBox.Show("请选择TIN保存路径");
                }
                else
                {
                    //生成点shape
                    Excel2Shape excel2shape = new Excel2Shape(textBox_point.Text);
                    excel2shape.CreateShapeFromExcel();

                    //获取shapefile
                    string path = excel2shape.path;
                    string name = excel2shape.name;

                    IWorkspaceFactory pWSFac = new ShapefileWorkspaceFactoryClass();
                    IFeatureWorkspace pFeatureWS = pWSFac.OpenFromFile(path , 0) as IFeatureWorkspace;
                    IFeatureClass pFeatureClass = pFeatureWS.OpenFeatureClass(name);
                    IField pField = pFeatureClass.Fields.get_Field(pFeatureClass.FindField("Z"));
                    //创建TIN
                    ITin pTin = Create_TIN(pFeatureClass , pField , outFolder);
                    ITinLayer pTinlayer = new TinLayerClass();
                    pTinlayer.Dataset = pTin;
                    pTinlayer.Name = strTinName;

                    pSceneControl.SceneGraph.Scene.AddLayer(pTinlayer as ILayer , true);

                    this.Close();
                }
              
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message + "创建TIN失败!");
            }

        }
        /// <summary>
        /// 创建TIN
        /// </summary>
        /// <param name="pFeatureClass">点要素类</param>
        /// <param name="pField">Z字段</param>
        /// <param name="pPath">路径</param>
        public ITin Create_TIN(IFeatureClass pFeatureClass , IField pField , string pPath)
        {
            IGeoDataset pGeoDataset = pFeatureClass as IGeoDataset;
            ITinEdit pTinEdit = new TinClass();
            pTinEdit.InitNew(pGeoDataset.Extent);
            object pObj = Type.Missing;

            pTinEdit.AddFromFeatureClass(pFeatureClass , null , pField , null ,
            esriTinSurfaceType.esriTinMassPoint , ref pObj);
            if (System.IO.File.Exists(pPath))
            {
                _3DCampus.helper.FolderHelper.DeleteFolder(pPath);
            }
            pTinEdit.SaveAs(pPath , ref pObj);
            pTinEdit.Refresh();
            return pTinEdit as ITin;

        }
        #endregion