C#+ArcEngine:shp矢量点转Tin(VS2010窗体+代码)C#+ArcEngine:shp矢量点转Tin(VS2010窗体+代码)C#+ArcEngine:shp矢量点转Tin(VS2010窗体+代码)C#+ArcEngine:shp矢量点转Tin(VS2010窗体+代码)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.Carto;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using System.IO;


namespace shp矢量点转Tin
{
    public partial class FormMain : Form
    {
        public FormMain()
        {
            ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);//重要的一句话
            InitializeComponent();
        }




        //选择shp矢量点文件
        IFeatureClass xjFeatureClass;
        private void 打开txtToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.axSceneControl1.Scene.ClearLayers();
            OpenFileDialog xjShpFileDialogshp = new OpenFileDialog();
            xjShpFileDialogshp.Title = "打开矢量点数据";
            xjShpFileDialogshp.Filter = "矢量文件(*.shp)|*.shp";

            if (xjShpFileDialogshp.ShowDialog() == DialogResult.OK)
            {
                string xjShpFileFullPath = xjShpFileDialogshp.FileName;
                shp点文件全路径ToolStripMenuItem.Text = xjShpFileFullPath;
                string xjShpFolder = System.IO.Path.GetDirectoryName(xjShpFileFullPath);
                string xjShpFilename = System.IO.Path.GetFileName(xjShpFileFullPath);

                IWorkspaceFactory xjWsF = new ShapefileWorkspaceFactory();
                IFeatureWorkspace xjFeatureWorkspace = (IFeatureWorkspace)xjWsF.OpenFromFile(xjShpFolder, 0);

                IWorkspace xjws = xjWsF.OpenFromFile(xjShpFolder, 0);
                IFeatureWorkspace xjFWs = xjws as IFeatureWorkspace;
                xjFeatureClass = xjFWs.OpenFeatureClass(xjShpFilename);
                IFeatureLayer xjFeatureLayer = new FeatureLayer();
                xjFeatureLayer.FeatureClass = xjFeatureClass;
                xjFeatureLayer.Name = xjFeatureClass.AliasName;


                ILayer xjShpLayer;
                xjShpLayer = xjFeatureLayer as ILayer;
                this.axSceneControl1.Scene.AddLayer(xjShpLayer, false);
            }
        }




        //选择Tin保存路径
        private void 选择Tin保存路径ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog xjTinSaveDialog = new SaveFileDialog();
            xjTinSaveDialog.Title = "选择TIN文件保存路径";
            xjTinSaveDialog.Filter = "TIN(*.tin)|*.tin";

            if (xjTinSaveDialog.ShowDialog() == DialogResult.OK)
            {
                string xjTINSavepath = xjTinSaveDialog.FileName;
                tin保存路径ToolStripMenuItem.Text = xjTINSavepath;
            }
        }




        //转换并显示Tin
        IGeoDataset xjGeoDataSet;
        IEnvelope xjEnvelopeExtent;
        IFields xjFields;
        IField xjField;
        private void 转换ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //1、创建Tin
            string TinSavePath = tin保存路径ToolStripMenuItem.Text;
            xjGeoDataSet = xjFeatureClass as IGeoDataset;
            xjEnvelopeExtent = new EnvelopeClass();
            xjEnvelopeExtent = xjGeoDataSet.Extent;
            xjFields = xjFeatureClass.Fields;
            xjField = xjFields.get_Field(4);//设置所用字段:height
            ITinEdit xjTinEdit = new TinClass();
            xjTinEdit.InitNew(xjEnvelopeExtent);
            try
            {
                xjTinEdit.AddFromFeatureClass(xjFeatureClass, null, xjField, null, esriTinSurfaceType.esriTinMassPoint);
            }
            catch
            {
                MessageBox.Show("创建TIN失败");
            }
            xjTinEdit.SaveAs(TinSavePath);
            xjTinEdit.StopEditing(false);

            //2、加载TIN
            IWorkspaceFactory TinWsF = new TinWorkspaceFactory();
            ITinWorkspace TinWs;
            ITin xjTin;
            ITinLayer TinLayer;
            ILayer xjLayer;
            FileInfo fileinfo = new FileInfo(TinSavePath);
            if (TinWsF.IsWorkspace(fileinfo.DirectoryName))
            {
                TinWs = TinWsF.OpenFromFile(fileinfo.DirectoryName, 0) as ITinWorkspace;
                xjTin = TinWs.OpenTin(fileinfo.Name);
                TinLayer = new TinLayerClass();
                TinLayer.Dataset = xjTin;
                xjLayer = TinLayer as ILayer;
                //显示
                this.axSceneControl1.Scene.AddLayer(xjLayer, true);
                this.axSceneControl1.SceneGraph.RefreshViewers();
            }
        }

    }

}


VS2010+ArcEngine10.1具体窗体+代码见:点击打开链接

VS2012+ArcEngine10.2见:点击打开链接

相关文章:

  • 2021-07-04
  • 2021-12-10
  • 2021-06-26
  • 2021-09-26
  • 2022-12-23
  • 2021-07-25
  • 2021-10-23
  • 2021-07-08
猜你喜欢
  • 2021-09-15
  • 2021-04-20
  • 2021-10-05
  • 2021-10-08
  • 2021-04-17
  • 2021-05-05
  • 2022-01-16
相关资源
相似解决方案