サーフェス オブジェクトは、さまざまな GetGeneralProperties() メソッドを使用してアクセスできる一般的なサーフェス プロパティを開示します。プロパティを計算して返す処理は、大量のリソースを消費するため、プロパティごとにメソッドを呼び出すのではなく、一度このメソッドを呼び出し、返されたオブジェクトを再使用することをお勧めします。TIN サーフェスとグリッド サーフェスには、サーフェス タイプ固有のプロパティがあります(それぞれ GetTinProperties() および GetGridProperties() によって返されます)。TIN サーフェスとグリッド サーフェスは、どちらも GetTerrainProperties() メソッドも実装しています。
次の例では、データベース内の最初のサーフェスの一般的なプロパティを取得し、次に、サーフェス タイプに応じて、TIN サーフェスまたはグリッド サーフェスのプロパティを取得します。
[CommandMethod("SurfaceProperties")]
public void SurfaceProperties()
{
using (Transaction ts = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
{
try
{
// Get the first surface in a document
// "doc" is the CivilApplication.ActiveDocument
ObjectId surfaceId = doc.GetSurfaceIds()[0];
CivSurface oSurface = surfaceId.GetObject(OpenMode.ForRead) as CivSurface;
// print out general properties:
GeneralSurfaceProperties genProps = oSurface.GetGeneralProperties();
String propsMsg = "\nGeneral Properties for " + oSurface.Name;
propsMsg += "\n-------------------";
propsMsg += "\nMin X: " + genProps.MinimumCoordinateX;
propsMsg += "\nMin Y: " + genProps.MinimumCoordinateY;
propsMsg += "\nMin Z: " + genProps.MinimumElevation;
propsMsg += "\nMax X: " + genProps.MaximumCoordinateX;
propsMsg += "\nMax Y: " + genProps.MaximumCoordinateY;
propsMsg += "\nMax Z: " + genProps.MaximumElevation;
propsMsg += "\nMean Elevation: " + genProps.MeanElevation;
propsMsg += "\nNumber of Points: " + genProps.NumberOfPoints;
propsMsg += "\n--";
editor.WriteMessage(propsMsg);
// Depending on the surface type, let's look at grid or TIN properties:
if (oSurface is TinSurface)
{
TinSurfaceProperties tinProps = ((TinSurface)oSurface).GetTinProperties();
propsMsg = "\nTIN Surface Properties for " + oSurface.Name;
propsMsg += "\n-------------------";
propsMsg += "\nMin Triangle Area: " + tinProps.MinimumTriangleArea;
propsMsg += "\nMin Triangle Length: " + tinProps.MinimumTriangleLength;
propsMsg += "\nMax Triangle Area: " + tinProps.MaximumTriangleArea;
propsMsg += "\nMax Triangle Length: " + tinProps.MaximumTriangleLength;
propsMsg += "\nNumber of Triangles: " + tinProps.NumberOfTriangles;
propsMsg += "\n--";
editor.WriteMessage(propsMsg);
}
else if (oSurface is GridSurface)
{
#region GetGridProperties
GridSurfaceProperties gridProps = ((GridSurface)oSurface).GetGridProperties();
propsMsg = "\\Grid Surface Properties for " + oSurface.Name;
propsMsg += "\n-------------------";
propsMsg += "\n X Spacing: " + gridProps.SpacingX;
propsMsg += "\n Y Spacing: " + gridProps.SpacingY;
propsMsg += "\n Orientation: " + gridProps.Orientation;
propsMsg += "\n--";
editor.WriteMessage(propsMsg);
#endregion
}
}
catch (System.Exception e) { editor.WriteMessage(e.Message); }
}
}