If you want to have all the power on how contours are created, you can always use the ‘ExtractContourAt()’ method. This method allows you to specified an elevation value at which the contours should be extracted, which in turn, gives you all the flexibility to extract contours using any kind of logic you will like. Of course, you want to insure the specified elevation is within the Surface’s elevation range.
The following command shows how the method is invoked to extract contours at a specified elevation, and how you can check the specified elevation is in range.
C#
[CommandMethod("CDS_ExtractSurfaceContoursAtElevation")]
public void CDS_ExtractSurfaceContoursAtElevation()
{
using (Transaction tr = startTransaction())
{
ITerrainSurface surface = getSurface() as ITerrainSurface;
if (surface == null) return;
double elevation = getDouble("elevation");
if (Double.IsNaN(elevation)) return;
if (elevationInSurfaceRange(elevation,
surface as CivilSurface))
{
ObjectIdCollection contours =
surface.ExtractContoursAt(elevation);
customizeContours(contours, _singleContourColor);
}
tr.Commit();
}
}
private bool elevationInSurfaceRange(double elevation,
CivilSurface surface)
{
GeneralSurfaceProperties properties =
surface.GetGeneralProperties();
if (elevation < properties.MinimumElevation ||
elevation > properties.MaximumElevation)
{
_editor.WriteMessage(
"\nSpecified elevation not in surface range.");
return false;
}
return true;
}
VB.NET
<CommandMethod("CDS_ExtractSurfaceContoursAtElevation")> _
Public Sub CDS_ExtractSurfaceContoursAtElevation()
Using tr As Transaction = startTransaction()
Dim surface As ITerrainSurface = TryCast(getSurface(),
ITerrainSurface)
If surface Is Nothing Then
Return
End If
Dim elevation As Double = getDouble("elevation")
If [Double].IsNaN(elevation) Then
Return
End If
If elevationInSurfaceRange(elevation,
TryCast(surface, CivilSurface)) Then
Dim contours As ObjectIdCollection =
surface.ExtractContoursAt(elevation)
customizeContours(contours, _singleContourColor)
End If
tr.Commit()
End Using
End Sub
Private Function elevationInSurfaceRange(elevation As Double,
surface As CivilSurface) As Boolean
Dim properties As GeneralSurfaceProperties =
surface.GetGeneralProperties()
If elevation < properties.MinimumElevation Or
elevation > properties.MaximumElevation Then
_editor.WriteMessage(
vbLf & "Specified elevation not in surface range.")
Return False
End If
Return True
End Function
As always, you can download the full source code from the Civilized Development repository.
Comments