23 #include "SpatialIndex.h"
25 using namespace SpatialIndex;
40 mList.append( d.getIdentifier() );
54 mStorageManager = StorageManager::createNewMemoryStorageManager();
58 unsigned int capacity = 10;
59 bool writeThrough =
false;
60 mStorage = StorageManager::createNewRandomEvictionsBuffer( *mStorageManager, capacity, writeThrough );
63 double fillFactor = 0.7;
64 unsigned long indexCapacity = 10;
65 unsigned long leafCapacity = 10;
66 unsigned long dimension = 2;
67 RTree::RTreeVariant variant = RTree::RV_RSTAR;
70 SpatialIndex::id_type indexId;
71 mRTree = RTree::createNewRTree( *mStorage, fillFactor, indexCapacity,
72 leafCapacity, dimension, variant, indexId );
79 delete mStorageManager;
84 double pt1[2], pt2[2];
89 return Region( pt1, pt2, 2 );
107 if ( !featureInfo( f, r,
id ) )
116 catch ( Tools::Exception &e )
119 QgsDebugMsg( QString(
"Tools::Exception caught: " ).arg( e.what().c_str() ) );
121 catch (
const std::exception &e )
124 QgsDebugMsg( QString(
"std::exception caught: " ).arg( e.what() ) );
128 QgsDebugMsg(
"unknown spatial index exception caught" );
138 if ( !featureInfo( f, r,
id ) )
147 QList<QgsFeatureId> list;
150 Region r = rectToRegion( rect );
152 mRTree->intersectsWithQuery( r, visitor );
159 QList<QgsFeatureId> list;
167 mRTree->nearestNeighborQuery( neighbors, p, visitor );
QgsFeatureId id() const
Get the feature id for this feature.
A rectangle specified with double values.
SpatialIndex::Region rectToRegion(QgsRectangle rect)
double yMaximum() const
Get the y maximum value (top side of rectangle)
QgsGeometry * geometry() const
Get the geometry object associated with this feature.
void visitNode(const INode &n)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QList< QgsFeatureId > nearestNeighbor(QgsPoint point, int neighbors)
returns nearest neighbors (their count is specified by second parameter)
QList< QgsFeatureId > & mList
QgisVisitor(QList< QgsFeatureId > &list)
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
double xMaximum() const
Get the x maximum value (right side of rectangle)
#define FID_TO_NUMBER(fid)
QgsSpatialIndex()
constructor - creates R-tree
QList< QgsFeatureId > intersects(QgsRectangle rect)
returns features that intersect the specified rectangle
bool insertFeature(QgsFeature &f)
add feature to index
void visitData(std::vector< const IData * > &v)
A class to represent a point geometry.
void visitData(const IData &d)
QgsRectangle boundingBox()
Returns the bounding box of this feature.
~QgsSpatialIndex()
destructor finalizes work with spatial index
bool featureInfo(QgsFeature &f, SpatialIndex::Region &r, QgsFeatureId &id)
bool deleteFeature(QgsFeature &f)
remove feature from index
double xMinimum() const
Get the x minimum value (left side of rectangle)