00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GEOS_INDEX_STRTREE_STRTREE_H
00020 #define GEOS_INDEX_STRTREE_STRTREE_H
00021
00022 #include <geos/export.h>
00023 #include <geos/index/strtree/ItemDistance.h>
00024 #include <geos/index/strtree/BoundablePair.h>
00025 #include <geos/index/strtree/AbstractSTRtree.h>
00026 #include <geos/index/SpatialIndex.h>
00027 #include <geos/geom/Envelope.h>
00028
00029 #include <vector>
00030
00031 #ifdef _MSC_VER
00032 #pragma warning(push)
00033 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
00034 #endif
00035
00036
00037 namespace geos {
00038 namespace index {
00039 namespace strtree {
00040 class Boundable;
00041 }
00042 }
00043 }
00044
00045 namespace geos {
00046 namespace index {
00047 namespace strtree {
00048
00064 class GEOS_DLL STRtree: public AbstractSTRtree, public SpatialIndex
00065 {
00066 using AbstractSTRtree::insert;
00067 using AbstractSTRtree::query;
00068
00069 private:
00070 class GEOS_DLL STRIntersectsOp: public AbstractSTRtree::IntersectsOp {
00071 public:
00072 bool intersects(const void* aBounds, const void* bBounds);
00073 };
00074
00082 std::auto_ptr<BoundableList> createParentBoundables(BoundableList* childBoundables, int newLevel);
00083
00084 std::auto_ptr<BoundableList> createParentBoundablesFromVerticalSlices(std::vector<BoundableList*>* verticalSlices, int newLevel);
00085
00086 STRIntersectsOp intersectsOp;
00087
00088 std::auto_ptr<BoundableList> sortBoundables(const BoundableList* input);
00089
00090 std::auto_ptr<BoundableList> createParentBoundablesFromVerticalSlice(
00091 BoundableList* childBoundables,
00092 int newLevel);
00093
00099 std::vector<BoundableList*>* verticalSlices(
00100 BoundableList* childBoundables,
00101 size_t sliceCount);
00102
00103
00104 protected:
00105
00106 AbstractNode* createNode(int level);
00107
00108 IntersectsOp* getIntersectsOp() {
00109 return &intersectsOp;
00110 }
00111
00112 public:
00113
00114 ~STRtree();
00115
00120 STRtree(std::size_t nodeCapacity=10);
00121
00122 void insert(const geom::Envelope *itemEnv,void* item);
00123
00124
00125
00126 static double avg(double a, double b) {
00127 return (a + b) / 2.0;
00128 }
00129
00130 static double centreY(const geom::Envelope *e) {
00131 return STRtree::avg(e->getMinY(), e->getMaxY());
00132 }
00133
00134 void query(const geom::Envelope *searchEnv, std::vector<void*>& matches) {
00135 AbstractSTRtree::query(searchEnv, matches);
00136 }
00137
00138 void query(const geom::Envelope *searchEnv, ItemVisitor& visitor) {
00139 return AbstractSTRtree::query(searchEnv, visitor);
00140 }
00141
00142 const void* nearestNeighbour(const geom::Envelope *env, const void* item, ItemDistance* itemDist);
00143 std::pair<const void*, const void*> nearestNeighbour(BoundablePair* initBndPair);
00144 std::pair<const void*, const void*> nearestNeighbour(ItemDistance* itemDist);
00145 std::pair<const void*, const void*> nearestNeighbour(BoundablePair* initBndPair, double maxDistance);
00146
00147 bool remove(const geom::Envelope *itemEnv, void* item) {
00148 return AbstractSTRtree::remove(itemEnv, item);
00149 }
00150 };
00151
00152 }
00153 }
00154 }
00155
00156
00157 #ifdef _MSC_VER
00158 #pragma warning(pop)
00159 #endif
00160
00161 #endif // GEOS_INDEX_STRTREE_STRTREE_H