This document is archived and information here might be outdated.  Recommended version.


How to interpolate spot heights and profile lines on a TIN (ArcObjects .NET 10.4 SDK)

How to interpolate spot heights and profile lines on a TIN


About interpolating spot heights and profiles

The following code example shows how to get z-values for points and polylines by interpolating heights for them off a triangulated irregular network (TIN).
The InterpolateShape geoprocessing tool can be used for this task. Consider using it instead of the ArcObjects application programming interface (API).
  1. Open a TIN and get the ITinSurface interface from it. See the following code example:
[C#]
// Open an existing TIN, edit the following path as appropriate.
ITinAdvanced2 Tin=new TinClass();
Tin.Init("c:\\project\\my_tin");

// Cast to ITinSurface.
ITinSurface TinSurf=Tin as ITinSurface;
[VB.NET]
' Open an existing TIN, edit the following path as appropriate.
Dim Tin As ITinAdvanced2=New TinClass()
Tin.Init("c:\project\my_tin")

' Cast to ITinSurface.
Dim TinSurf As ITinSurface=TryCast(Tin, ITinSurface)
  1. For an x,y location, use a point and call ITinSurface.GetElevation (derived from ISurface.GetElevation) to interpolate a z-value.
  2. Use ITinSurface.IsVoidZ (derived from ISurface.IsVoidZ) on the resulting z-value to determine if the query location is on or off the surface. See the following code example:
[C#]
// Get the 2D geometry you want to obtain z-values for.
// In this example, first make a simple point.
IPoint MyPoint=new PointClass();
MyPoint.X=741626;
MyPoint.Y=4341457;

// Call the GetElevation method to get the z-value for the x,y location.
double z;
z=TinSurf.GetElevation(MyPoint);

// This is how to test if the point does not fall on the surface.
if (TinSurf.IsVoidZ(z))
    MessageBox.Show("Point is off surface!");
[VB.NET]
' Get the 2D geometry you want to obtain z-values for.
' In this example, first make a simple point.
Dim MyPoint As IPoint=New PointClass()
MyPoint.X=741626
MyPoint.Y=4341457

' Call the GetElevation method to get the z-value for the x,y location.
Dim z As Double
z=TinSurf.GetElevation(MyPoint)

' This is how to test if the point does not fall on the surface.
If TinSurf.IsVoidZ(z) Then
    MessageBox.Show("Point is off surface!")
End If
  1. To profile a line, pass a polyline to ITinSurface.InterpolateShape (derived from ISurface.InterpolateShape).
  2. Test if the resulting shape is null. If so, the line falls entirely off the surface. See the following code example:
[C#]
// Profile a two point line.
// The point object created earlier is being reused to construct the line.
IPointCollection MyLine=new PolylineClass();
object Missing=Type.Missing;
MyLine.AddPoint(MyPoint, ref Missing, ref Missing);

MyPoint.X=741636;
MyPoint.Y=4341467;
MyLine.AddPoint(MyPoint, ref Missing, ref Missing);

// The TINs' method, InterpolateShape, profiles the input 2D line
// and outputs a ZAware, 3D, polyline. 
// InterpolateShape can also be used for points and polygons.
IGeometry ProfiledLine;
TinSurf.InterpolateShape(MyLine as IGeometry, out ProfiledLine, ref Missing);

// The output line will be null if the input does not cross the surface.
if (ProfiledLine == null)
    MessageBox.Show("Line is off surface!");
[VB.NET]
' Profile a two point line.
' The point object created earlier is being reused to construct the line.
Dim MyLine As IPointCollection=New PolylineClass()
Dim Missing As Object=Type.Missing
MyLine.AddPoint(MyPoint, Missing, Missing)

MyPoint.X=741636
MyPoint.Y=4341467
MyLine.AddPoint(MyPoint, Missing, Missing)

' The TINs' method, InterpolateShape, profiles the input 2D line
' and outputs a ZAware, 3D, polyline.
' InterpolateShape can also be used for points and polygons.
Dim ProfiledLine As IGeometry
TinSurf.InterpolateShape(TryCast(MyLine, IGeometry), ProfiledLine, Missing)

' The output line will be null if the input does not cross the surface.
If ProfiledLine Is Nothing Then
    MessageBox.Show("Line is off surface!")
End If






To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcGIS for Desktop Basic: 3D Analyst ArcGIS for Desktop Basic: 3D Analyst
ArcGIS for Desktop Standard: 3D Analyst ArcGIS for Desktop Standard: 3D Analyst
ArcGIS for Desktop Advanced: 3D Analyst ArcGIS for Desktop Advanced: 3D Analyst
Engine Developer Kit Engine: 3D Analyst