Processing a spatial query involves performing complex and heavy geometric operations. For example, you can find an element near a certain point from the 10 thousand elements. The brute-force solution is to perform a series of searches across the entire range, requiring massive disk access and massive geometric condition tests. Creating a spatial index for a group of elements can greatly improve the search execution efficiency. Spatial Data indexes refer to spatial indexes. When using spatial indexes, a group of elements will be indexed.
The FMEOReader object uses the setConstraints method to provide some Spatial indexing functions (for details, see the section "Reading Features From Using Constraints" of a Dataset ), FME spatial index object FMEOSpatialIndex provides a precise and easy-to-use spatial index based on the R + tree data structure. Shows the attributes and methods of FMEOSpatialIndex:
If your application reads data from the format provided by the native spatial index (which can be determined by the FMEOReader's getProperties method), you can easily use the setConstraints method of FMEOReader to access the local index, even so, your application can still benefit from FME spatial index objects. For example, if there is an Elevation Grid, local spatial indexes can improve performance, in addition, the FME spatial index object is useful for creating a spatial index with a small number of elements in a massive source dataset.
In this chapter, you can learn the following:
- Create and open a spatial index
- Index part of Elements
- Perform a space query on the indexed Elements
- Disable spatial indexes
Create and open a spatial index
You must use the createSpatialIndex method of the FMEOSession object to create the control index. Once created, you can use the open method as follows:
Dim fmeDirectives As FMEOStringArray
Dim sFileName As String
SFileName = sSpatialDir & "\ SpatialIndex. ffs"
Set fmeDirectives = m_fmeSession.createStringArray
FmeDirectives. append ("PASSPHRASE ")
FmeDirectives. append ("test ")
FmeDirectives. append ("BYTE_ORDER ")
FmeDirectives. append ("BIG_ENDIAN ")
Set m_fmeSpatialIndex = m_fmeSession.createSpatialIndex (_
SFileName, "WRITE", fmeDirectives)
M_fmeSpatialIndex.open
The first parameter of the createSpatialIndex method is to store the name and path of the index element. ffs (FME feature store) is used as the extension of the element data file. Another file has the same name as it, but the extension is. fsi (FME spatial index) is used to store FME spatial indexes.
The second parameter is a string value used to specify the access mode. It can be WRITE or READ. You can use WRITE to create a new index and READ to access an existing index, when a spatial index is created and read, the data file and the associated index file must exist. Otherwise, an exception occurs. In READ mode, adding an element to the index by the view causes an exception. When a spatial index is created and written, the data file does not need to exist. If the file already exists, it will be overwritten. In WRITE mode, no elements will be returned if you try to query the index, when the spatial index is enabled, the access mode cannot be changed. To change the WRITE and READ modes, You need to disable the spatial index and re-open it.
The third parameter is a string array that contains some parameters to control the creation of spatial indexes. The parameter is provided as a key-Value Pair and supports the following parameters:
Index Elements
The store method of the FMEOSpatialIndex object is used to add a factor to the spatial index at a time in the open WRITE mode. For example:
Dim lEntries As Integer
Dim I As Integer
LEntries = m_fmeFeatureVector.entries
For I = 0 To lEntries-1
Call m_fmeSpatialIndex.store (m_fmeFeatureVector.element (I ))
Next I
The elements in m_fmeFeatureVector will be indexed, because the store method creates a deep copy for each element in the. ffs file. Changing the elements in m_fmeFeatureVector does not affect the spatial index.
Execution space Query
The FMEOSpatialIndex object provides a set of query methods for executing spatial queries. The query method requires the FMEOFeature object as a parameter.
The query code is similar to the following code:
Dim fmeQueryFeature As FMEOFeature
Set fmeQueryFeature = m_fmeSession.createFeature
Call fmeQueryFeature. addCoordinate (0, 0, 0)
Call fmeQueryFeature. addCoordinate (1, 1, 0)
Call m_fmeSpatialIndex.queryEnvelope (fmeQueryFeature)
FMEOSpatialIndex maintains a set of selected elements through space query. The following code uses the fetch method to repeatedly extract the result set.
Dim fmeDataFeature As FMEOFeature
Dim bEnd As Boolean
Set fmeDataFeature = m_fmeSession.createFeature
BEnd = False
Do While bEnd = False
BEnd = m_fmeSpatialIndex.fetch (fmeDataFeature)
Loop
When the result set ends, the first element is returned when fetch is called again (assuming that the result set is not empty ).
Disable spatial indexes
You can use the close method to disable spatial indexes.
Call m_fmeSpatialIndex.Close (True)
References:
Building Applications with FME Objects February 2005
Reprinted please indicate the source http://www.cnblogs.com/booolee