24 #include "SpatialIndex.h"
26 using namespace SpatialIndex;
37 void visitNode(
const INode& n )
override
40 void visitData(
const IData& d )
override
42 mList.append( d.getIdentifier() );
45 void visitData( std::vector<const IData*>& v )
override
49 QList<QgsFeatureId>& mList;
56 : mNewIndex( newIndex ) {}
58 void visitNode(
const INode& n )
override
61 void visitData(
const IData& d )
override
63 SpatialIndex::IShape* shape;
65 mNewIndex->insertData( 0, 0, *shape, d.getIdentifier() );
69 void visitData( std::vector<const IData*>& v )
override
73 SpatialIndex::ISpatialIndex* mNewIndex;
93 virtual IData* getNext()
override
95 RTree::Data* ret = mNextData;
102 virtual bool hasNext()
override {
return mNextData != 0; }
105 virtual uint32_t
size()
override { Q_ASSERT( 0 &&
"not available" );
return 0; }
108 virtual void rewind()
override { Q_ASSERT( 0 &&
"not available" ); }
114 SpatialIndex::Region r;
116 while ( mFi.nextFeature( f ) )
120 mNextData =
new RTree::Data( 0, 0, r,
id );
128 RTree::Data* mNextData;
148 : QSharedData( other )
153 double low[] = { DBL_MIN, DBL_MIN };
154 double high[] = { DBL_MAX, DBL_MAX };
155 SpatialIndex::Region query( low, high, 2 );
157 other.
mRTree->intersectsWithQuery( query, visitor );
166 void initTree( IDataStream* inputStream = 0 )
169 mStorage = StorageManager::createNewMemoryStorageManager();
172 double fillFactor = 0.7;
173 unsigned long indexCapacity = 10;
174 unsigned long leafCapacity = 10;
175 unsigned long dimension = 2;
176 RTree::RTreeVariant variant = RTree::RV_RSTAR;
179 SpatialIndex::id_type indexId;
182 mRTree = RTree::createAndBulkLoadNewRTree( RTree::BLM_STR, *inputStream, *mStorage, fillFactor, indexCapacity,
183 leafCapacity, dimension, variant, indexId );
185 mRTree = RTree::createNewRTree( *mStorage, fillFactor, indexCapacity,
186 leafCapacity, dimension, variant, indexId );
220 if (
this != &other )
227 double pt1[2], pt2[2];
232 return Region( pt1, pt2, 2 );
260 catch ( Tools::Exception &e )
263 QgsDebugMsg( QString(
"Tools::Exception caught: " ).arg( e.what().c_str() ) );
265 catch (
const std::exception &e )
268 QgsDebugMsg( QString(
"std::exception caught: " ).arg( e.what() ) );
272 QgsDebugMsg(
"unknown spatial index exception caught" );
291 QList<QgsFeatureId> list;
296 d->mRTree->intersectsWithQuery( r, visitor );
303 QList<QgsFeatureId> list;
311 d->mRTree->nearestNeighborQuery( neighbors, p, visitor );