等高線は、ExtractContours()、ExtractContoursAt()、ExtractMajorContours()、ExtractMinorContours() を使用して、サーフェス(TIN とグリッドの両方)から AutoCAD 図面オブジェクトとして抽出することができます。これらのメソッドは、ITerrainSurface インタフェースによって定義され、すべてのサーフェス クラスに実装されています。
ExtractContours() メソッドには 4 つのバージョンがあります。4 つのパラメータ指定は最も単純です。他に標高の範囲と間隔の指定があります。追加のスムージング パラメータを指定して、抽出したポリラインを滑らかにする次の 2 つのメソッド バージョンもあります。抽出された等高線は最適化 AutoCAD ポリライン オブジェクトで、このメソッドは抽出されたすべてのオブジェクトの ID を含む ObjectIdCollection を返します。このオブジェクトはサーフェスから独立しており、下のサーフェスに影響を与えずに操作することができます。
次の例では、ランダムなサーフェスを作成し、2 つの方法で等高線を抽出します。
// Setup: creates a new, random surface // TinSurface surface = CreateRandomSurface("Example Surface"); // Extract contours and print information about them: ObjectIdCollection contours; double contourInterval = 50.0; contours = surface.ExtractContours(contourInterval); write("# of extracted contours: " + contours.Count + "\n"); int totalVertices = 0; for (int i = 0; i < contours.Count; i++) { ObjectId contourId = contours[i]; // Contours are lightweight Polyline objects: Polyline contour = contourId.GetObject(OpenMode.ForRead) as Polyline; write(String.Format("Contour #{0} length:{1}, # of vertices:{2}\n", i, contour.Length, contour.NumberOfVertices)); totalVertices += contour.NumberOfVertices; } // Extract contours with smoothing: contours = surface.ExtractContours(contourInterval, ContourSmoothingType.AddVertices, 10); int totalVerticesSmoothed = 0; foreach (ObjectId contourId in contours) { Polyline contour = contourId.GetObject(OpenMode.ForRead) as Polyline; totalVerticesSmoothed += contour.NumberOfVertices; } // Compare smoothing by adding vertices: write(String.Format("Effects of smoothing:\n total vertices no smoothing: {0}\n total vertices with smoothing: {1}\n", totalVertices, totalVerticesSmoothed)); // Extract contours in a range: double startRange = 130.0; double endRange = 190.0; contours = surface.ExtractContours(contourInterval, startRange, endRange); write("# of extracted contours in range: " + contours.Count + "\n"); // You can also extract contours in a range with smoothing: // contours = surface.ExtractContours(contourInterval, startRange, endRange, // ContourSmoothingType.SplineCurve, 10);