横断を作成する

横断は、GetSectionSources() が返す可能な SectionSources のコレクションを取得することによって、SampleLineGroup に作成されます。これは、SectionSourceObjectIds のコレクションです。既定では、このコレクションには、すべての有効なサーフェスおよびコリドー シェイプの SectionSource が含まれます。SectionSource が関連付けられているオブジェクトのタイプは、その SourceType プロパティに保持されています。特定のサーフェスまたはコリドー シェイプを抽出するには、対応する SectionSource.IsSampled プロパティを True に設定します。

次の例では、線形を選択するように求めるプロンプトがユーザに表示されます。新しい SampleLineGroup が作成され、次に SampleLineGroupSectionSourceCollection が反復されます。 TIN サーフェスの SectionSource が抽出されます。

// prompt user to select an alignment, and then create a new SampleLineGroup for the Alignment:
ObjectId alignmentId = promptForEntity("Select an Alignment to add sample lines to:", typeof(Alignment));
Alignment alignment = ts.GetObject(alignmentId, OpenMode.ForWrite) as Alignment;
ObjectId sampleLineGroupId = SampleLineGroup.Create("New Group", alignmentId);
SampleLineGroup sampleLineGroup = ts.GetObject(sampleLineGroupId, OpenMode.ForWrite) as SampleLineGroup;

// Create a sample line.
ObjectId sampleLineId = SampleLine.Create("sample line 1", sampleLineGroupId, alignment.StartingStation);


// Get the available section sources for the SampleLineGroup
// SampleLineGroup must be OpenMode.ForWrite for this to work:
SectionSourceCollection sectionSources = sampleLineGroup.GetSectionSources();
_editor.WriteMessage("Number of section sources: {0}\n", sectionSources.Count);

ObjectId surfaceId = ObjectId.Null;
foreach (SectionSource sectionSource in sectionSources)
{
    _editor.WriteMessage("Section source is sampled: {0} update mode: {1} type: {2}\n", sectionSource.IsSampled, sectionSource.UpdateMode, sectionSource.SourceType);
    // if it's a TinSurface, let's sample it:
    if (sectionSource.SourceType == SectionSourceType.TinSurface)
    {
        // save for later:
        surfaceId = sectionSource.SourceId;
        // we can also get more info about the source type from its objectId
        TinSurface sourceSurface = ts.GetObject(sectionSource.SourceId, OpenMode.ForRead) as TinSurface;
        _editor.WriteMessage("Adding TIN surface {0} to Section Sources for SampleLineGroup\n", sourceSurface.Name);
        sectionSource.IsSampled = true;
    }
}

サーフェスおよびコリドー シェイプは、数量テーブルの土量計算にも使用されます。これらのサーフェスとシェイプは、MaterialSectionSource で表されます。SectionSource オブジェクトとは異なり、isSampled プロパティは読み込み専用で、ソースの抽出には使用されません。サーフェスまたはシェイプを抽出するには、QTOMaterial.Add() メソッドを使用して QTOMaterial に追加します。

QTOMaterial にサーフェスまたはシェイプを追加するには、複数の手順があります。まず、SampleLineGroup.MaterialLists.Add () メソッドを使用して、QTOMaterialListSampleLineGroup に追加します。 次に、 QTOMaterialQTOMaterialListに追加します。 最後に、サーフェスまたはシェイプを QTOMaterial に追加します。

下のコードは、この手順を示しています。上の例からの続きです(SectionSource として使用される保存された surfaceID を使用)。

// Material Sources are grouped in QTOMaterialLists, so we create a QTOMaterialList first:
QTOMaterialList qtoMaterialList = sampleLineGroup.MaterialLists.Add("New Material List");
// Add the material:
QTOMaterial qtoMaterial = qtoMaterialList.Add("New Material");
// Add the material item to either a surface or a corridor shape code.  
// Here we use the TIN surface ID for EG sampled above:             
qtoMaterial.Add(surfaceId);

// This is how you access all the Material Section Sources:
// Get the material sources
MaterialSectionSourceCollection materialSectionSources = sampleLineGroup.GetMaterialSectionSources();
_editor.WriteMessage("Number of material section sources: {0}\n", materialSectionSources.Count);

// Note that unlike SectionSource, isSampled is read-only
foreach (MaterialSectionSource materialSectionSource in materialSectionSources)
{
    _editor.WriteMessage("Material source is sampled: {0} update mode: {1} type: {2} material: {3}\n", materialSectionSource.IsSampled,
        materialSectionSource.UpdateMode, materialSectionSource.SourceType, materialSectionSource.Material);
}