XY イベント クラスの作成

''' <summary>
''' XYイベントクラスの作成
''' </summary>
''' <param name="pTable">テーブル</param>
''' <param name="pSpatialReference">空間参照</param>
''' <param name="XFieldName">Xフィールド</param>
''' <param name="YFieldName">Yフィールド</param>
''' <param name="ZFieldName">Zフィールド</param>
''' <returns>フィーチャクラス</returns>
''' <remarks></remarks>
Public Function CreateXYEventSource(
                                   ByVal pTable As ITable,
                                   ByVal pSpatialReference As ISpatialReference,
                                   Optional ByVal XFieldName As String = "X",
                                   Optional ByVal YFieldName As String = "Y",
                                   Optional ByVal ZFieldName As String = "") As IFeatureClass

    'XYEvent2FieldsProperties オブジェクトの作成
    Dim pXYEvent2FieldsProperties As IXYEvent2FieldsProperties = New XYEvent2FieldsPropertiesClass()
    pXYEvent2FieldsProperties.XFieldName = XFieldName
    pXYEvent2FieldsProperties.YFieldName = YFieldName
    pXYEvent2FieldsProperties.ZFieldName = ZFieldName 'Z値を設定する場合のオプション設定

    'ソース テーブルからNameオブジェクトの取得
    Dim pDataset As IDataset = CType(pTable, IDataset)
    Dim pSourceName As IName = pDataset.FullName

    'XYEventSourceNameオブジェクトの作成
    Dim pXYEventSourceName As IXYEventSourceName = New XYEventSourceNameClass()
    pXYEventSourceName.EventProperties = pXYEvent2FieldsProperties
    pXYEventSourceName.EventTableName = pSourceName
    pXYEventSourceName.SpatialReference = pSpatialReference '空間参照

    'XY イベント ソースの作成
    Dim pEventName As IName = CType(pXYEventSourceName, IName)
    Dim pXYEventSource As IXYEventSource = CType(pEventName.Open(), IXYEventSource)

    'IFeatureClass型へキャスト
    Dim pFeatureClass As IFeatureClass = CType(pXYEventSource, IFeatureClass)

    Return pFeatureClass
End Function