GEOS  3.6.1
STRtree.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2006 Refractions Research Inc.
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU Lesser General Public Licence as published
10  * by the Free Software Foundation.
11  * See the COPYING file for more information.
12  *
13  **********************************************************************
14  *
15  * Last port: index/strtree/STRtree.java rev. 1.11
16  *
17  **********************************************************************/
18 
19 #ifndef GEOS_INDEX_STRTREE_STRTREE_H
20 #define GEOS_INDEX_STRTREE_STRTREE_H
21 
22 #include <geos/export.h>
23 #include <geos/index/strtree/ItemDistance.h>
24 #include <geos/index/strtree/BoundablePair.h>
25 #include <geos/index/strtree/AbstractSTRtree.h> // for inheritance
26 #include <geos/index/SpatialIndex.h> // for inheritance
27 #include <geos/geom/Envelope.h> // for inlines
28 
29 #include <vector>
30 
31 #ifdef _MSC_VER
32 #pragma warning(push)
33 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
34 #endif
35 
36 // Forward declarations
37 namespace geos {
38  namespace index {
39  namespace strtree {
40  class Boundable;
41  }
42  }
43 }
44 
45 namespace geos {
46 namespace index { // geos::index
47 namespace strtree { // geos::index::strtree
48 
64 class GEOS_DLL STRtree: public AbstractSTRtree, public SpatialIndex
65 {
68 
69 private:
70  class GEOS_DLL STRIntersectsOp: public AbstractSTRtree::IntersectsOp {
71  public:
72  bool intersects(const void* aBounds, const void* bBounds);
73  };
74 
82  std::auto_ptr<BoundableList> createParentBoundables(BoundableList* childBoundables, int newLevel);
83 
84  std::auto_ptr<BoundableList> createParentBoundablesFromVerticalSlices(std::vector<BoundableList*>* verticalSlices, int newLevel);
85 
86  STRIntersectsOp intersectsOp;
87 
88  std::auto_ptr<BoundableList> sortBoundables(const BoundableList* input);
89 
90  std::auto_ptr<BoundableList> createParentBoundablesFromVerticalSlice(
91  BoundableList* childBoundables,
92  int newLevel);
93 
99  std::vector<BoundableList*>* verticalSlices(
100  BoundableList* childBoundables,
101  size_t sliceCount);
102 
103 
104 protected:
105 
106  AbstractNode* createNode(int level);
107 
109  return &intersectsOp;
110  }
111 
112 public:
113 
114  ~STRtree();
115 
120  STRtree(std::size_t nodeCapacity=10);
121 
122  void insert(const geom::Envelope *itemEnv,void* item);
123 
124  //static double centreX(const geom::Envelope *e);
125 
126  static double avg(double a, double b) {
127  return (a + b) / 2.0;
128  }
129 
130  static double centreY(const geom::Envelope *e) {
131  return STRtree::avg(e->getMinY(), e->getMaxY());
132  }
133 
134  void query(const geom::Envelope *searchEnv, std::vector<void*>& matches) {
135  AbstractSTRtree::query(searchEnv, matches);
136  }
137 
138  void query(const geom::Envelope *searchEnv, ItemVisitor& visitor) {
139  return AbstractSTRtree::query(searchEnv, visitor);
140  }
141 
142  const void* nearestNeighbour(const geom::Envelope *env, const void* item, ItemDistance* itemDist);
143  std::pair<const void*, const void*> nearestNeighbour(BoundablePair* initBndPair);
144  std::pair<const void*, const void*> nearestNeighbour(ItemDistance* itemDist);
145  std::pair<const void*, const void*> nearestNeighbour(BoundablePair* initBndPair, double maxDistance);
146 
147  bool remove(const geom::Envelope *itemEnv, void* item) {
148  return AbstractSTRtree::remove(itemEnv, item);
149  }
150 };
151 
152 } // namespace geos::index::strtree
153 } // namespace geos::index
154 } // namespace geos
155 
156 
157 #ifdef _MSC_VER
158 #pragma warning(pop)
159 #endif
160 
161 #endif // GEOS_INDEX_STRTREE_STRTREE_H
void query(const geom::Envelope *searchEnv, std::vector< void *> &matches)
Queries the index for all items whose extents intersect the given search Envelope.
Definition: STRtree.h:134
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:53
Base class for STRtree and SIRtree.
Definition: AbstractSTRtree.h:132
void query(const geom::Envelope *searchEnv, ItemVisitor &visitor)
Queries the index for all items whose extents intersect the given search Envelope and applies an Item...
Definition: STRtree.h:138
A query-only R-tree created using the Sort-Tile-Recursive (STR) algorithm. For two-dimensional spatia...
Definition: STRtree.h:64
Abstract class defines basic insertion and query operations supported by classes implementing spatial...
Definition: SpatialIndex.h:47
A test for intersection between two bounds, necessary because subclasses of AbstractSTRtree have diff...
Definition: AbstractSTRtree.h:166
A visitor for items in an index.
Definition: ItemVisitor.h:29
virtual void insert(const void *bounds, void *item)
Also builds the tree, if necessary.
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
double getMaxY() const
double getMinY() const
void query(const void *searchBounds, std::vector< void *> &foundItems)
Also builds the tree, if necessary.
A node of the STR tree.
Definition: AbstractNode.h:42
A spatial object in an AbstractSTRtree.
Definition: Boundable.h:25
std::vector< Boundable * > BoundableList
A list of boundables. TODO: use a list.
Definition: AbstractSTRtree.h:44
IntersectsOp * getIntersectsOp()
Definition: STRtree.h:108