Changes between Version 1 and Version 2 of FDORfc63


Ignore:
Timestamp:
May 17, 2012, 12:22:14 PM (12 years ago)
Author:
danstoica
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • FDORfc63

    v1 v2  
    2727== Motivation ==
    2828
    29 The motivation
    30 
    31 == Implications ==
     29The motivation is the poor performance of the FDO secondary filter. The worst case is Polygon intersect Polygon due to the potential complexity of the filter polygon and the amount of candidate polygons. The algorithm used for each candidate polygon is:
     30
     31    1. check if any points of candidatePoly are inside filter polygon
     32    2. check if any points of filterPoly are inside candidate polygon
     33    3. do pairwise edge intersection
     34
     35Note that all 3 steps are correct, all of them are necessary and point-in-polygon/segment-to-segment tests are tuned for performance. Meaning further fine tuning is not a solution. The root problem is that the filter polygon is traversed entirely for each step and multiple times and this RFC is addressing it.
     36
     37== Proposed Solution ==
     38
     39The solution is to create a Spatial Index for the filter polygon where each segment of the polygon has an entry. This way all the steps 1-3 will benefit by limiting the segments to check to those in the area of interest. For example, the point-in-polygon test will run a spatial query using the X-ray bounding box as search area. Therefore, instead of traversing all the segments, only a few will be processed for X-ray intersections.
     40
     41This RFC describes the Spatial Index API. The implementation of the FDO secondary filter using the Spatial Index will be the topic of a separate RFC.
     42
     43
     44{{{
     45/// \ingroup (enums)
     46/// \brief
     47/// FdoSpatialIndexMode is an enumeration of the types of the Spatial Index,
     48/// representing the granularity.
     49enum FdoSpatialIndexMode
     50{
     51    /// Mode #1 - Regular Spatial Index: one entry in the rtree for the entire geometry
     52    FdoSpatialIndex_ByGeometriesBoundingBox = 0,
     53
     54    /// Mode #2 - The geometries are broken into segments and each segment has an entry in the rtree.
     55    /// The segment index is contiguous over parts and subparts.
     56    FdoSpatialIndex_BySegmentsMultipleFeatures = 1,
     57
     58    /// Mode #3 - Just one geometry is allowed. The geometry is broken into segments
     59    /// and each segment has an entry in the rtree. The part and subpart are encoded to allow
     60    /// for sorting and fast processing.
     61    FdoSpatialIndex_BySegmentsSingleFeature = 2
     62};
     63
     64/// \brief
     65/// Spatial Index class.
     66class FdoSpatialIndex : public FdoIDisposable
     67{
     68    friend class FdoSpatialIndexIterator;
     69
     70public:
     71    /// \brief
     72    /// Creates a Spatial Index instance
     73    ///
     74    /// \param mode
     75    /// Input Type of the spatial index
     76        ///
     77        /// \return
     78    /// Returns A spatial index instance
     79    ///
     80    FDO_SPATIAL_API static FdoSpatialIndex* Create(FdoSpatialIndexMode mode = FdoSpatialIndex_ByGeometriesBoundingBox);
     81
     82        /// \brief
     83        /// Retrieves the Spatial index mode set at creation time
     84        ///
     85        /// \return
     86    /// Returns the Spatial index mode set at creation
     87    ///
     88    FDO_SPATIAL_API FdoSpatialIndexMode GetMode();
     89
     90        /// \brief
     91        /// Inserts a feature into the spatial index given a bounding box
     92        ///
     93        /// \remarks
     94    /// Applies only for Mode #1. The Featid is not encoded.
     95    ///
     96        /// \param featId
     97    /// Input The feature identifier
     98        /// \param featId
     99    /// Input A bounding box
     100        ///
     101        /// \return
     102    /// Returns Nothing
     103    ///
     104    FDO_SPATIAL_API void InsertObject(FdoInt64 featId, FdoIEnvelope *ext);
     105
     106        /// \brief
     107        /// Inserts a feature into the spatial index given a bounding box
     108        ///
     109        /// \remarks
     110        /// Applies for Mode #2 and #3. The Featid is encoded as follows:
     111        /// Mode #2:
     112    ///      32 bits (0-31)  - 1-based featId #
     113    ///      32 bits (32-63) - vertex # (contiguous)
     114    ///
     115        /// Mode #3:
     116        ///              0 bits          - featId # (will be ignored)
     117    ///      16 bits (0-15)  - part # (for multi-features) max. 65534
     118    ///      16 bits (16-31) - subpart # (e.g. polygons with interior rings) max 65534
     119    ///      32 bits (32-63) - vertex #
     120    ///
     121        /// \param featId
     122    /// Input The feature identifier
     123        /// \param featId
     124    /// Input A geometry in FGF format
     125        ///
     126        /// \return
     127    /// Returns Nothing
     128    ///
     129    FDO_SPATIAL_API void InsertObject(FdoInt32 featId, FdoByteArray* fgfArray);
     130
     131        /// \brief
     132        /// Returns the extent of the spatial index
     133        ///
     134        /// \return
     135    /// Returns The extents of the spatial index
     136    ///
     137    FDO_SPATIAL_API FdoIEnvelope* GetTotalExtent();
     138
     139        /// \brief
     140        /// Decodes a marker returned by the Spatial index iterator.
     141        /// Applies only for Mode #2, BySegmentsMultipleFeatures.
     142        ///
     143        /// \param marker
     144    /// Input A marker returned by the Spatial index iterator
     145        /// \param featId
     146    /// Output The featId
     147        /// \param iVertex
     148    /// Output The index of the segment in the original geometry, 1-based
     149        ///
     150        /// \return
     151    /// Returns Nothing
     152    ///
     153    FDO_SPATIAL_API void     DecodeMarker(FdoInt64 marker, FdoInt32 &featId, FdoInt32 &iSegment);
     154
     155        /// \brief
     156        /// Decodes a marker returned by the Spatial index iterator.
     157        /// Applies only for Mode #3, BySegmentsSingleFeature.
     158        ///
     159        /// \param marker
     160    /// Input A marker returned by the Spatial index iterator
     161        /// \param iPart
     162        /// Output The index of the part in a multi-geometry, e.g. a polygon # in a multi-polygon
     163        /// \param iSubPart
     164        /// Output The index of the subpart in a geometry, e.g. a ring # in a polygon
     165        /// \param iVertex
     166    /// Output The index of the segment in the sub-part, 1-based
     167        ///
     168        /// \return
     169    /// Returns Nothing
     170    ///
     171    FDO_SPATIAL_API void     DecodeMarker(FdoInt64 marker, FdoInt32 &iPart, FdoInt32 &iSubPart, FdoInt32 &iSegment);
     172
     173/// \cond DOXYGEN-IGNORE
     174    virtual void Dispose();
     175/// \endcond
     176   
     177protected:
     178    FdoSpatialIndex(FdoSpatialIndexMode mode = FdoSpatialIndex_ByGeometriesBoundingBox);
     179
     180    virtual ~FdoSpatialIndex();
     181};
     182
     183/// \brief
     184/// Spatial Index Iterator class
     185class FdoSpatialIndexIterator
     186{
     187public:
     188        /// \brief
     189        /// Creates a Spatial Index Iterator instance
     190        ///
     191    /// \param si
     192    /// Input A Spatial Index instance
     193        /// \param minx
     194        /// Input The minimim X of the bounding box representing the search area
     195        /// \param miny
     196        /// Input The minimim Y of the bounding box representing the search area
     197        /// \param maxx
     198        /// Input The maximum X of the bounding box representing the search area
     199        /// \param maxy
     200        /// Input The maximum Y of the bounding box representing the search area
     201        ///
     202        /// \return
     203    /// Returns A Spatial Index Iterator instance
     204    ///
     205    FDO_SPATIAL_API FdoSpatialIndexIterator(FdoSpatialIndex* si, double minx, double miny, double maxx, double maxy);
     206
     207        /// \brief
     208        /// Iterator over the features selected in the the search area
     209        ///
     210        /// \return
     211    /// Returns an encoded marker. Zero (0) return value stands for the end of fetch
     212    ///
     213    FDO_SPATIAL_API FdoInt64 GetNextObject();
     214
     215    FDO_SPATIAL_API ~FdoSpatialIndexIterator();
     216};
     217
     218}}}
     219
     220== How to use this API ==
     221
     222The following code illustrates how to
     223
     224== Managed FDO API ==
     225
     226The FDO Managed Interfaces will be updated in a similar manner to reflect the proposed changes.
    32227
    33228