GEOS  3.8.0dev
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 {
67 
68 private:
69  class GEOS_DLL STRIntersectsOp: public AbstractSTRtree::IntersectsOp {
70  public:
71  bool intersects(const void* aBounds, const void* bBounds) override;
72  };
73 
81  std::unique_ptr<BoundableList> createParentBoundables(BoundableList* childBoundables, int newLevel) override;
82 
83  std::unique_ptr<BoundableList> createParentBoundablesFromVerticalSlices(std::vector<BoundableList*>* verticalSlices,
84  int newLevel);
85 
86  STRIntersectsOp intersectsOp;
87 
88  std::unique_ptr<BoundableList> sortBoundables(const BoundableList* input) override;
89 
90  std::unique_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) override;
107 
108  IntersectsOp*
109  getIntersectsOp() override
110  {
111  return &intersectsOp;
112  }
113 
114 public:
115 
116  ~STRtree() override;
117 
122  STRtree(std::size_t nodeCapacity = 10);
123 
124  void insert(const geom::Envelope* itemEnv, void* item) override;
125 
126  //static double centreX(const geom::Envelope *e);
127 
128  static double
129  avg(double a, double b)
130  {
131  return (a + b) / 2.0;
132  }
133 
134  static double
135  centreY(const geom::Envelope* e)
136  {
137  return STRtree::avg(e->getMinY(), e->getMaxY());
138  }
139 
140  void
141  query(const geom::Envelope* searchEnv, std::vector<void*>& matches) override
142  {
143  AbstractSTRtree::query(searchEnv, matches);
144  }
145 
146  void
147  query(const geom::Envelope* searchEnv, ItemVisitor& visitor) override
148  {
149  return AbstractSTRtree::query(searchEnv, visitor);
150  }
151 
152  const void* nearestNeighbour(const geom::Envelope* env, const void* item, ItemDistance* itemDist);
153  std::pair<const void*, const void*> nearestNeighbour(BoundablePair* initBndPair);
154  std::pair<const void*, const void*> nearestNeighbour(ItemDistance* itemDist);
155  std::pair<const void*, const void*> nearestNeighbour(BoundablePair* initBndPair, double maxDistance);
156  std::pair<const void*, const void*> nearestNeighbour(STRtree* tree, ItemDistance* itemDist);
157 
158  bool
159  remove(const geom::Envelope* itemEnv, void* item) override
160  {
161  return AbstractSTRtree::remove(itemEnv, item);
162  }
163 
164 };
165 
166 } // namespace geos::index::strtree
167 } // namespace geos::index
168 } // namespace geos
169 
170 
171 #ifdef _MSC_VER
172 #pragma warning(pop)
173 #endif
174 
175 #endif // GEOS_INDEX_STRTREE_STRTREE_H
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:59
Base class for STRtree and SIRtree.
Definition: AbstractSTRtree.h:140
void query(const void *searchBounds, std::vector< void * > &foundItems)
Also builds the tree, if necessary.
void query(const geom::Envelope *searchEnv, std::vector< void * > &matches) override
Queries the index for all items whose extents intersect the given search Envelope.
Definition: STRtree.h:141
void query(const geom::Envelope *searchEnv, ItemVisitor &visitor) override
Queries the index for all items whose extents intersect the given search Envelope and applies an Item...
Definition: STRtree.h:147
double getMinY() const
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:174
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.
double getMaxY() const
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
A node of the STR tree.
Definition: AbstractNode.h:43
std::vector< Boundable * > BoundableList
A list of boundables. TODO: use a list.
Definition: AbstractSTRtree.h:44
IntersectsOp * getIntersectsOp() override
Definition: STRtree.h:109