FMEOReader can access data in any supported format.
FMEOReader returns two types of elements: schema (schema) elements and data elements. schema elements are used to describe the dataset model. Each supported format has a pattern. A pattern element is a data model of a type of element. It describes attributes, coordinate systems, and geometric element types.
In this chapter, you can learn:
- Create reader
- Open reader
- Get reader settings
- Get activity reader information
- Return mode elements
- Return data elements
- Close reader
Create Reader
It must be created through the createReader method of the FMEOSession object, as shown below:
Dim fmeDirectives As FMEOStringArray
Set fmeDirectives = m_fmeSession.createStringArray
FmeDirectives. append ("OUTPUT_STATS ")
FmeDirectives. append ("NO ")
Set m_fmeReader = m_fmeSession.createReader ("SHAPE ",_
False, fmeDirectives)
The format type representation is unique and used to control the creation of reader. Some are the first parameters in the createReader method. SHAPE is used to create ESRI Shapefile reader. The following is its description:
Note: The read and write operations on the FME object depend on the Reader/Writer row in the preceding table.
The second parameter of createReader is a Boolean value used to determine whether to create a feature disk cache. If your application needs to access the feature set multiple times, it will cache to improve performance, multiple accesses to the dataset cache can reduce I/O requests, create a disk-based spatial index for the FME object to quickly and randomly access elements and allow advanced space and attribute queries,
The third parameter of createReader is a string array, which contains the parameters in the following table, which are paired with names and values:
Open Reader
Once a reader is created, you can open the specified dataset. The following code is used to read the c: \ SHAPE:
Dim fmekeywords As FMEOStringArray
Set fmeKeywords = m_fmeSession.createStringArray
FmeKeywords. append ("MEASURES_AS_Z ")
FmeKeywords. append ("YES ")
FmeKeywords. append ("IDs ")
FmeKeywords. append ("roads. shp ")
FmeKeywords. append ("IDs ")
FmeKeywords. append ("rivers. shp ")
Call m_fmeReader.open ("c: \ shape", fmeKeywords)
The first parameter. For ESRI Shapefile reader, a dataset directory is required. Other readers may need a dataset file, database, or URL. For details, see Quick Facts table.
The second parameter is a string array. The names and values are displayed in pairs to control reader operations.
Reader Parameters
The FMEODialog object is used to create and open a new reader. The sourcePrompt method of FMEODialog displays a dialog box and obtains user data.
For example:
Note: The FMEODialog object is only used on WINDOWS and is unavailable in other operating systems.
The SourcePrompt method returns the user-specified parameters and passes the returned parameters to the FMEOSession createReader and FMEOReader open methods:
Public Sub SourcePrompt (sSourceDir As String)
Dim fmeDialog As FMEODialog
Dim fmeDirectives As FMEOStringArray
Dim fmeKeywords As FMEOStringArray
Dim sDataset As String
Dim sFormat As String
Dim bCompleted As Boolean
Set fmeDialog = m_fmeSession.createDialog
Set fmeDirectives = m_fmeSession.createStringArray
Call fmeDirectives. append ("LIMIT_FORMATS ")
Call fmeDirectives. append ("MIF ")
BCompleted = fmeDialog. SourcePrompt ("MIF", sSourceDir ,_
SFormat, sDataset, fmeDirectives)
If bCompleted = True Then
Set m_fmeReader = m_fmeSession.createReader (sFormat ,_
True, fmeDirectives)
Set fmeKeywords = m_fmeSession.createStringArray
Call m_fmeReader.open (sDataset, fmeKeywords)
M_bReaderOpened = True
End If
End Sub
The following are parameters of the SourcePrompt method:
Obtain information from the active Reader
In the input data source session box, the redmost user can select a format from the format list. If your application needs to access the list of available formats, you can use the getAvailableFormats method of the FMEODialog object. You can use the getAvailableFormats method of the FMEODialog object to obtain detailed information about available formats.
The following code displays a dialog box to display all the information of the specified Reader:
Public Sub GetReaderInfo (ByVal sFormatName As String)
Dim lPos As Long
Dim sMsg As String
Dim sDirection As String
Dim bSpatialIndex As Boolean
Dim fmeDialog As FMEODialog
Dim fmeFormats As FMEOStringArray
Dim fmeFormatInfo As FMEOStringArray
Set fmeDialog = m_fmeSession.createDialog
Set fmeFormats = m_fmeSession.createStringArray
Set fmeFormatInfo = m_fmeSession.createStringArray
Call fmeDialog. getAvailableFormats (fmeFormats)
LPos = GetIndex (fmeFormats, sFormatName)
If lPos =-1 Then
SMsg = "Format not available :"
SMsg = sMsg & sFormatName & vbCrLf
MsgBox sMsg, vbOKOnly, "GetReaderInfo"
Exit Sub
End If
Call fmeDialog. getFormatInfoEx (sFormatName, fmeFormatInfo)
SMsg = "Format:" & sFormatName
LPos = GetIndex (fmeFormatInfo, "FORMAT_LONG_NAME ")
SMsg = sMsg & vbCrLf & "Long Name :"
SMsg = sMsg & fmeFormatInfo. element (lPos + 1)
LPos = GetIndex (fmeFormatInfo, "DATASET_TYPE ")
SMsg = sMsg & vbCrLf & "Dataset Type :"
SMsg = sMsg & fmeFormatInfo. element (lPos + 1)
LPos = GetIndex (fmeFormatInfo, "INPUT_OUTPUT ")
SMsg = sMsg & vbCrLf & "Direction :"
SMsg = sMsg & fmeFormatInfo. element (lPos + 1)
LPos = GetIndex (fmeFormatInfo, "FILE_EXTENSIONS ")
SMsg = sMsg & vbCrLf & "File Filter :"
SMsg = sMsg & fmeFormatInfo. element (lPos + 1)
LPos = GetIndex (fmeFormatInfo, "COORD_SYSTEM_AWARE ")
SMsg = sMsg & vbCrLf & "Coordinate System Aware :"
SMsg = sMsg & fmeFormatInfo. element (lPos + 1)
LPos = GetIndex (fmeFormatInfo, "SOURCE_SETTINGS ")
SMsg = sMsg & vbCrLf & "Has Source Settings :"
SMsg = sMsg & fmeFormatInfo. element (lPos + 1)
LPos = GetIndex (fmeFormatInfo, "DESTINATION_SETTINGS ")
SMsg = sMsg & vbCrLf & "Has Destination Settings :"
SMsg = sMsg & fmeFormatInfo. element (lPos + 1)
LPos = GetIndex (fmeFormatInfo, "AUTOMATED_TRANSLATION ")
SMsg = sMsg & vbCrLf & "Supports Automated Translation :"
SMsg = sMsg & fmeFormatInfo. element (lPos + 1)
MsgBox sMsg, vbOKOnly, "GetReaderInfo"
End Sub
The information returned by the getFormatInfoEx method of the FMEODialog object is the name value pair. The following table lists the names:
The extra information about the FMEOReader object can be obtained using its getProperties method, for example:
Set fmeProperties = m_fmeSession.createStringArray
Call m_fmeReader.getProperties ("fme_prop_spatial_index ",_
FmeProperties)
Read mode (Schema) Elements
Before reading data elements, you do not need to force read mode elements to continue reading data elements. Each time you call the readSchema method, a schema element is returned. This method returns True or False, the following code writes all the schema elements of the dataset to the log:
Public Sub LogSchemaFeatures ()
Dim bLastSchema As Boolean
Dim fmeSchemaFeature As FMEOFeature
BLastSchema = False
Set fmeSchemaFeature = m_fmeSession.createFeature
Do While bLastSchema = False
BLastSchema = m_fmeReader.readSchema (fmeSchemaFeature)
If bLastSchema = False Then
Call m_fmeLogfile.logFeature (fmeSchemaFeature, 1, 1)
End If
Loop
End Sub
Read data elements
Once your program is created and reader is enabled, you are ready to start reading data elements. You can use the read method. This method returns one element at a time and returns TRUE if no element is read, otherwise, FALSE is returned. The following code uses reader to read all requests and write the feature vector.
BEnd = False
Do While bEnd = False
Set fmeDataFeature = m_fmeSession.createFeature
BEnd = m_fmeReader.read (fmeDataFeature)
If bEnd = False Then
Call fmeFeatureVector. append (fmeDataFeature)
End If
Loop
Note: A New FMEOFeature object is created before the read method is called each time. To avoid overwriting the elements of the previous read.
Restrictions
By executing simple space query and attribute query, the FME object is restricted to read only matching elements. After reading the last element, your application can use the setConstraints method to filter new elements.
Use the setConstraints method to specify constraints for the FMEOFeature object and use the attribute to specify fme_search_type for filtering. The following table lists the values supported by fme_search_type:
If your application filters input datasets multiple times, it is strongly recommended that you enable the cache when creating a reader.
After the cache is enabled, all input elements will be cached at the first read. Before the setConstraints method is called, a new reader will be created from the cache.
When the processed original dataset has a spatial index (for example, SDE), the Cache Usage is different.
Close Reader
Close using the close Method
Call m_fmeReader.Close
You can request Visual Basic to destroy the object reference.
Set m_fmeReader = Nothing
This will lead to the release of reader-related resources.
References:
Building Applications with FME Objects February 2005
Reprinted please indicate the source http://www.cnblogs.com/booolee