學習《Building Applications with FME Objects》 之六 轉換要素


這個API可以非常容易的在格式之間做轉換,首先打開reader和writer(具體操作前兩篇已經有介紹),可以簡單的使用FMEODialog的xlatePrompt方法顯示窗口,同時允許用戶輸入reader和writer的參數:

image

注意:FMEODialog對象僅能用於WINDOWS平台

 

下面的代碼演示了該方法返回的參數並傳遞給reader和writer:

 

Public Sub TranslationPrompt(sSourceDir As String, _
                                sDestDir As String)
    Dim sDestDataset As String
    Dim sDestFormat As String
    Dim sSrcDataset As String
    Dim sSrcFormat As String
    Dim bCompleted As Boolean
    Dim bEnd As Boolean
    Dim fmeFeature As FMEOFeature
    Dim fmeDialog As FMEODialog
    Dim fmeSrcDirectives As FMEOStringArray
    Dim fmeDestDirectives As FMEOStringArray
    Dim fmeKeywords As FMEOStringArray
    Set fmeKeywords = m_fmeSession.createStringArray
    Set fmeDialog = m_fmeSession.createDialog
    Set fmeSrcDirectives = m_fmeSession.createStringArray
    Set fmeDestDirectives = m_fmeSession.createStringArray
    bCompleted = fmeDialog.xlatePrompt("MIF", sSourceDir, _
                 "MIF", sDestDir, _
                 sSrcFormat, sSrcDataset, fmeSrcDirectives, _
                 sDestFormat, sDestDataset, fmeDestDirectives)
    If bCompleted = True Then
        Set m_fmeReader = m_fmeSession.createReader( _
                                    sSrcFormat, _
                                    True, fmeSrcDirectives)
        Call m_fmeReader.open(sSrcDataset, fmeKeywords)
        Set m_fmeWriter = m_fmeSession.createWriter( _
                                            sDestFormat, _
                                            fmeDestDirectives)
        Call m_fmeWriter.open(sDestDataset, fmeKeywords)
End Sub

xlatePrompt方法支持的參數:

image

 

如何源和目標的參數中都提供了TITLE值,那么優先采用目標參數中設定的TITLE值。

 

一旦reader和writer被打開,就可以簡單的做要素轉換,從reader寫到writer,代碼如下:

bEnd = False
Do While bEnd = False
    bEnd = m_fmeReader.readSchema(fmeFeature)
    If bEnd = False Then
        Call m_fmeWriter.addSchema(fmeFeature)
    End If
Loop
bEnd = False
Do While bEnd = False
    bEnd = m_fmeReader.read(fmeFeature)
    If bEnd = False Then
        Call m_fmeWriter.write(fmeFeature)
    End If
Loop

 

提示:FMEOWriter的addSchema和write方法會清空傳遞給它的要素,如果你還打算在寫入后繼續使用該要素,那么在寫入前先對該要素進行clone(克隆)。

 

一旦所有的要素被轉換完畢,就需要關閉reader和writer,如下:

Call m_fmeReader.Close

Call m_fmeWriter.Close

 

 

 

 

參考資料:

《Building Applications with FME Objects》February 2005

轉載請注明文章來源 http://www.cnblogs.com/booolee


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2021 ITdaan.com