HOW TO
Developers frequently want to convert data from one format to another. This example illustrates how to convert from a 3D FeatureClass to a TIN.
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
Get help from ArcGIS experts
Download the Esri Support App