In the past two days, I wrote a 3D campus display program for others, using the second development of SceneControl. DOM and TIN must be used to construct a three-dimensional terrain. Now let's talk about the process of generating TIN Based on the path:
(1) generate point shapefile Based on the Excel file
(2) generate TIN using the AddFromFeatureClass method of ITinEdit
The high-end data format is as follows:
The operation interface is as follows:
:
Generate TIN:
The code is easy to understand, as follows:
# Region create TIN private void button_ OK _Click (object sender, EventArgs e) {try {strTinName = textBox_TINName.Text; outFolder = textBox_outpath.Text; if (strTinName = ") {MessageBox. show ("Enter the TIN name! ");} Else if (outFolder =" ") {MessageBox. show ("select TIN save path");} else {// generate vertex shape Excel2Shape excel2shape = new Excel2Shape (textBox_point.Text); excel2shape. createShapeFromExcel (); // obtain the shapefile string path = excel2shape. path; string name = excel2shape. name; IWorkspaceFactory pWSFac = new ShapefileWorkspaceFactoryClass (); IFeatureWorkspace pFeatureWS = pWSFac. openFromFile (path, 0) as IFeatureWork Space; IFeatureClass pFeatureClass = pFeatureWS. openFeatureClass (name); IField pField = pFeatureClass. fields. get_Field (pFeatureClass. findField ("Z"); // create 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 + "failed to create TIN! ");}} /// <Summary> /// create TIN /// </summary> /// <param name = "pFeatureClass"> point element class </param> /// <param name = "pField"> Z field </param> // <param name = "pPath"> path </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