Most of the time when working with contours, we want to work with a range starting at some elevation, ending at some other elevation, and using a specific interval. Fortunately, the API provides this functionality through overloaded ‘ExtractContours()’ methods.
The first overload take an elevation interval. The range is created starting at the surface’s minimum elevation and ending at its maximum elevation. These two values are determined by the ‘GeneralSurfaceProperties’ of the surface object. As we can see in the following example, it is very simple to create contours at a specified interval.
C#
[CommandMethod("CDS_ExtractSurfaceContoursAtInterval")]
public void CDS_ExtractSurfaceContoursAtInterval()
{
using (Transaction tr = startTransaction())
{
ITerrainSurface surface = getSurface() as ITerrainSurface;
if (surface == null) return;
double interval = getDouble("interval");
if (Double.IsNaN(interval)) return;
ObjectIdCollection contours =
surface.ExtractContours(interval);
customizeContours(contours, _intervalContoursColor);
tr.Commit();
}
}
VB.NET
<CommandMethod("CDS_ExtractSurfaceContoursAtInterval")> _
Public Sub CDS_ExtractSurfaceContoursAtInterval()
Using tr As Transaction = startTransaction()
Dim surface As ITerrainSurface = TryCast(getSurface(),
ITerrainSurface)
If surface Is Nothing Then
Return
End If
Dim interval As Double = getDouble("interval")
If [Double].IsNaN(interval) Then
Return
End If
Dim contours As ObjectIdCollection = surface.ExtractContours(
interval)
customizeContours(contours, _intervalContoursColor)
tr.Commit()
End Using
End Sub
We can further customize the behavior by specifying the minimum and maximum elevation to utilize together with the interval. This other example does just that.
C#
[CommandMethod("CDS_ExtractSurfaceContoursFromToElevationRange")]
public void CDS_ExtractSurfaceContoursFromToElevationRange()
{
using (Transaction tr = startTransaction())
{
ITerrainSurface surface = getSurface() as ITerrainSurface;
if (surface == null) return;
double minElevation = getDouble("minimum elevation");
if (Double.IsNaN(minElevation)) return;
double maxElevation = getDouble("maximum elevation");
if (Double.IsNaN(maxElevation)) return;
double interval = getDouble("interval");
if (Double.IsNaN(interval)) return;
ObjectIdCollection contours =
surface.ExtractContours(
minElevation, maxElevation, interval);
customizeContours(contours, _rangedContoursColor);
tr.Commit();
}
}
VB.NET
<CommandMethod("CDS_ExtractSurfaceContoursFromToElevationRange")> _
Public Sub CDS_ExtractSurfaceContoursFromToElevationRange()
Using tr As Transaction = startTransaction()
Dim surface As ITerrainSurface = TryCast(getSurface(),
ITerrainSurface)
If surface Is Nothing Then
Return
End If
Dim minElevation As Double = getDouble("minimum elevation")
If [Double].IsNaN(minElevation) Then
Return
End If
Dim maxElevation As Double = getDouble("maximum elevation")
If [Double].IsNaN(maxElevation) Then
Return
End If
Dim interval As Double = getDouble("interval")
If [Double].IsNaN(interval) Then
Return
End If
Dim contours As ObjectIdCollection = surface.ExtractContours(
minElevation, maxElevation, interval)
customizeContours(contours, _rangedContoursColor)
tr.Commit()
End Using
End Sub
As you can see, these methods are implemented as part of the ‘ITerrainSurface’ interface, which means they can be used with TIN and Grid surfaces, The ‘ExtractContours()’ methods provide great flexibility to extract contour information from a surface, and their functionality is what most users require. Next week, we will take a look at an even more flexible method provided by ‘ITerrainSurface’.
P.S. I refactored some of the code from last week to apply it to this week’s examples. I recommend you download the latest source from the Civilized Development Repository at BitBucket.
Comments