STRtree.h

00001 /**********************************************************************
00002  *
00003  * GEOS - Geometry Engine Open Source
00004  * http://geos.osgeo.org
00005  *
00006  * Copyright (C) 2006 Refractions Research Inc.
00007  *
00008  * This is free software; you can redistribute and/or modify it under
00009  * the terms of the GNU Lesser General Public Licence as published
00010  * by the Free Software Foundation. 
00011  * See the COPYING file for more information.
00012  *
00013  **********************************************************************
00014  *
00015  * Last port: index/strtree/STRtree.java rev. 1.11
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/AbstractSTRtree.h> // for inheritance
00024 #include <geos/index/SpatialIndex.h> // for inheritance
00025 #include <geos/geom/Envelope.h> // for inlines
00026 
00027 #include <vector>
00028 
00029 #ifdef _MSC_VER
00030 #pragma warning(push)
00031 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
00032 #endif
00033 
00034 // Forward declarations
00035 namespace geos {
00036         namespace index { 
00037                 namespace strtree { 
00038                         class Boundable;
00039                 }
00040         }
00041 }
00042 
00043 namespace geos {
00044 namespace index { // geos::index
00045 namespace strtree { // geos::index::strtree
00046 
00062 class GEOS_DLL STRtree: public AbstractSTRtree, public SpatialIndex
00063 {
00064 using AbstractSTRtree::insert;
00065 using AbstractSTRtree::query;
00066 
00067 private:
00068         class GEOS_DLL STRIntersectsOp: public AbstractSTRtree::IntersectsOp {
00069                 public:
00070                         bool intersects(const void* aBounds, const void* bBounds);
00071         };
00072 
00080         std::auto_ptr<BoundableList> createParentBoundables(BoundableList* childBoundables, int newLevel);
00081 
00082         std::auto_ptr<BoundableList> createParentBoundablesFromVerticalSlices(std::vector<BoundableList*>* verticalSlices, int newLevel);
00083 
00084         STRIntersectsOp intersectsOp;
00085 
00086         std::auto_ptr<BoundableList> sortBoundables(const BoundableList* input);
00087 
00088         std::auto_ptr<BoundableList> createParentBoundablesFromVerticalSlice(
00089                         BoundableList* childBoundables,
00090                         int newLevel);
00091 
00097         std::vector<BoundableList*>* verticalSlices(
00098                         BoundableList* childBoundables,
00099                         size_t sliceCount);
00100 
00101 
00102 protected:
00103 
00104         AbstractNode* createNode(int level);
00105         
00106         IntersectsOp* getIntersectsOp() {
00107                 return &intersectsOp;
00108         }
00109 
00110 public:
00111 
00112         ~STRtree();
00113 
00118         STRtree(std::size_t nodeCapacity=10);
00119 
00120         void insert(const geom::Envelope *itemEnv,void* item);
00121 
00122         //static double centreX(const geom::Envelope *e);
00123 
00124         static double avg(double a, double b) {
00125                 return (a + b) / 2.0;
00126         }
00127 
00128         static double centreY(const geom::Envelope *e) {
00129                 return STRtree::avg(e->getMinY(), e->getMaxY());
00130         }
00131 
00132         void query(const geom::Envelope *searchEnv, std::vector<void*>& matches) {
00133                 AbstractSTRtree::query(searchEnv, matches);
00134         }
00135 
00136         void query(const geom::Envelope *searchEnv, ItemVisitor& visitor) {
00137                 return AbstractSTRtree::query(searchEnv, visitor);
00138         }
00139 
00140         bool remove(const geom::Envelope *itemEnv, void* item) {
00141                 return AbstractSTRtree::remove(itemEnv, item);
00142         }
00143 };
00144 
00145 } // namespace geos::index::strtree
00146 } // namespace geos::index
00147 } // namespace geos
00148 
00149 
00150 #ifdef _MSC_VER
00151 #pragma warning(pop)
00152 #endif
00153 
00154 #endif // GEOS_INDEX_STRTREE_STRTREE_H

Generated on 23 Sep 2013 for GEOS by  doxygen 1.4.7