HOW TO

Create a TIN from a 3D FeatureClass using ArcObjects

Last Published: April 25, 2020

Summary

Developers frequently want to convert data from one format to another. This example illustrates how to convert from a 3D FeatureClass to a TIN.

Procedure

This Visual Basic for Applications code sample assumes the first layer in the active DataFrame is 3D Points. See Related Information below for the link to ArcObjects Online; refer to it for descriptions of the input to the AddFromFeatureClass method on ITinEdit.


Code:
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument

' Assume the first layer in the map is 3D points.
Dim pFLayer As IFeatureLayer
Set pFLayer = pMxDoc.ActiveView.FocusMap.Layer(0)

Dim pFClass As IFeatureClass
Set pFClass = pFLayer.FeatureClass

Dim pFields As IFields
Set pFields = pFClass.Fields

' Heights for TIN will come from shape geometry.
' Height field is therefore 'Shape' field. Use an alternate field
' if heights come from numeric attribute rather than geometry.
Dim pHeightField As IField
Set pHeightField = pFields.Field(pFields.FindField(pFClass.ShapeFieldName))

Dim pGDS As IGeoDataset
Set pGDS = pFClass

Dim pEnv As IEnvelope
Set pEnv = pGDS.Extent
Set pEnv.SpatialReference = pGDS.SpatialReference

Dim pTinEdit As ITinEdit
Set pTinEdit = New Tin

' If the envelope used has its spatial ref set (as it does in this
' example), the output TIN will use it.
pTinEdit.InitNew pEnv

pTinEdit.AddFromFeatureClass pFClass, Nothing, pHeightField, Nothing, esriTinMassPoint

pTinEdit.SaveAs "c:\temp\test_tin"
pTinEdit.StopEditing False

Dim pTLayer As ITinLayer
Set pTLayer = New TinLayer
Set pTLayer.Dataset = pTinEdit

Dim pLayer As ILayer
Set pLayer = pTLayer

pLayer.Name = "tin"

' Add the resulting TIN as a layer to the map.
pMxDoc.ActiveView.FocusMap.AddLayer pTLayer

Article ID:000004168

Software:
  • ArcMap 8 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic