How to perform surface analysis on a terrain dataset


Performing surface analysis on a terrain dataset

The following code example shows how to get a dynamic surface object from a terrain and use it for surface analysis:
A variety of geoprocessing tools can be used to perform analysis on a terrain, such as the Interpolate Shape and Surface Contour tools. Consider using them instead of the ArcObjects application programming interface (API).
  1. Have the terrain create a DynamicSurface. See the following code example:
[C#]
// Surface analysis on a terrain is performed via a dynamic surface.
// Obtain a dynamic surface using the ITerrain interface.
IDynamicSurface DynSurf = Terrain.CreateDynamicSurface();
[VB.NET]
' Surface analysis on a terrain is performed via a dynamic surface.
' Obtain a dynamic surface using the ITerrain interface.
Dim DynSurf As IDynamicSurface = Terrain.CreateDynamicSurface()
  1. Extract a derivative surface from the DynamicSurface, either a triangulated irregular network (TIN) or raster, and perform the analysis on that surface. See the following code example:
[C#]
// In ArcGIS 9.2 and 9.3, you can perform TIN extraction and rasterization via
// the IDynamicSurface interface. Analysis is then performed on these
// derived datasets. TINs typically have to be subsets because they 
// can't get too large (for example, a few million points). Rasterization can 
// be performed on the terrain's full extent if desired.
ITin Tin;
IEnvelope Env = new EnvelopeClass();
Env = Terrain.Extent;
Env.Expand(0.1, 0.1, true);
Tin = DynSurf.GetTin(Env, 10.0, false, null);
[VB.NET]
' In ArcGIS 9.2 and 9.3, you can perform TIN extraction and rasterization via
' the IDynamicSurface interface. Analysis is then performed on these
' derived datasets. TINs typically have to be subsets because they
' can't get too large (for example, a few million points). Rasterization can
' be performed on the terrain's full extent if desired.
Dim Tin As ITin
Dim Env As IEnvelope = New EnvelopeClass()
Env = Terrain.Extent
Env.Expand(0.1, 0.1, True)
Tin = DynSurf.GetTin(Env, 0R, False, Nothing)
  1. In the current release, perform analysis directly on the DynamicSurface. See the following code example:
[C#]
// In current versions of ArcGIS, you can do more directly on the dynamic surface without
// the need for extracting a TIN or raster.
// Here, you interpolate a point directly on the terrain's dynamic surface.
IDynamicSurface3 DynSurf3 = DynSurf as IDynamicSurface3;
IPoint InPoint = new PointClass();
InPoint.X = Env.XMin + (Env.XMax - Env.XMin);
InPoint.Y = Env.YMin + (Env.YMax - Env.YMin);
IGeometry OutPoint;
object Missing = Type.Missing;
DynSurf3.InterpolateShape(InPoint, 0.0,
    esriSurfaceInterpolationType.esriLinearInterpolation, null, out OutPoint, ref
    Missing);

// If the same thing needed to be done with multiple shapes, it would be
// more efficienet to call IDynamicSurface3.InterpolateFeatureClass.
DynSurf3.InterpolateFeatureClass(InFeatureClass, null, 0.0,
    esriSurfaceInterpolationType.esriLinearInterpolation, OutFeatureClass, null, ref
    Missing);
[VB.NET]
' In current versions of ArcGIS, you can do more directly on the dynamic surface without
' the need for extracting a TIN or raster.
' Here, you interpolate a point directly on the terrain's dynamic surface.
Dim DynSurf3 As IDynamicSurface3 = TryCast(DynSurf, IDynamicSurface3)
Dim InPoint As IPoint = New PointClass()
InPoint.X = Env.XMin + (Env.XMax - Env.XMin)
InPoint.Y = Env.YMin + (Env.YMax - Env.YMin)
Dim OutPoint As IGeometry
Dim Missing As Object = Type.Missing
DynSurf3.InterpolateShape(InPoint, 0R, esriSurfaceInterpolationType.esriLinearInterpolation, Nothing, OutPoint, Missing)

' If the same thing needed to be done with multiple shapes, it would be
' more efficienet to call IDynamicSurface3.InterpolateFeatureClass.
DynSurf3.InterpolateFeatureClass(InFeatureClass, Nothing, 0R, esriSurfaceInterpolationType.esriLinearInterpolation, OutFeatureClass, Nothing, _
                                 Missing)






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
ArcView: 3D Analyst ArcView: 3D Analyst
ArcEditor: 3D Analyst ArcEditor: 3D Analyst
ArcInfo: 3D Analyst ArcInfo: 3D Analyst
Engine Developer Kit Engine Runtime: 3D