24 #include "SpatialIndex.h" 46 mList.append( d.getIdentifier() );
49 void visitData( std::vector<const IData*>& v )
override 64 : mNewIndex( newIndex ) {}
71 SpatialIndex::IShape* shape;
73 mNewIndex->insertData( 0,
nullptr, *shape, d.getIdentifier() );
77 void visitData( std::vector<const IData*>& v )
override 81 SpatialIndex::ISpatialIndex* mNewIndex;
96 , mNextData( nullptr )
109 RTree::Data* ret = mNextData;
116 virtual bool hasNext()
override {
return nullptr != mNextData; }
119 virtual uint32_t
size()
override { Q_ASSERT( 0 &&
"not available" );
return 0; }
122 virtual void rewind()
override { Q_ASSERT( 0 &&
"not available" ); }
128 SpatialIndex::Region r;
130 while ( mFi.nextFeature( f ) )
134 mNextData =
new RTree::Data( 0,
nullptr, r,
id );
142 RTree::Data* mNextData;
171 double low[] = { DBL_MIN, DBL_MIN };
172 double high[] = { DBL_MAX, DBL_MAX };
173 SpatialIndex::Region query( low, high, 2 );
175 other.
mRTree->intersectsWithQuery( query, visitor );
184 void initTree( IDataStream* inputStream =
nullptr )
187 mStorage = StorageManager::createNewMemoryStorageManager();
190 double fillFactor = 0.7;
191 unsigned long indexCapacity = 10;
192 unsigned long leafCapacity = 10;
193 unsigned long dimension = 2;
194 RTree::RTreeVariant variant = RTree::RV_RSTAR;
197 SpatialIndex::id_type indexId;
200 mRTree = RTree::createAndBulkLoadNewRTree( RTree::BLM_STR, *inputStream, *mStorage, fillFactor, indexCapacity,
201 leafCapacity, dimension, variant, indexId );
203 mRTree = RTree::createNewRTree( *mStorage, fillFactor, indexCapacity,
204 leafCapacity, dimension, variant, indexId );
242 if (
this != &other )
251 return SpatialIndex::Region( pt1, pt2, 2 );
269 SpatialIndex::Region r;
280 catch ( Tools::Exception &e )
285 catch (
const std::exception &e )
292 QgsDebugMsg(
"unknown spatial index exception caught" );
300 SpatialIndex::Region r;
316 d->mRTree->intersectsWithQuery( r, visitor );
326 double pt[2] = { point.
x(), point.
y() };
329 d->mRTree->nearestNeighborQuery( neighbors, p, visitor );
Wrapper for iterator of features from vector data provider or vector layer.
virtual uint32_t size() override
returns the total number of entries available in the stream.
A rectangle specified with double values.
virtual bool hasNext() override
returns true if there are more items in the stream.
SpatialIndex::IStorageManager * mStorage
Storage manager.
QgsSpatialIndex & operator=(const QgsSpatialIndex &other)
Implement assignment operator.
SpatialIndex::ISpatialIndex * mRTree
R-tree containing spatial index.
bool deleteFeature(const QgsFeature &f)
Remove feature from index.
QList< QgsFeatureId > intersects(const QgsRectangle &rect) const
Returns features that intersect the specified rectangle.
QgsSpatialIndexData(const QgsFeatureIterator &fi)
QList< QgsFeatureId > nearestNeighbor(const QgsPoint &point, int neighbors) const
Returns nearest neighbors (their count is specified by second parameter)
void visitNode(const INode &n) override
A geometry is the spatial representation of a feature.
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
void initTree(IDataStream *inputStream=nullptr)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QgsSpatialIndexCopyVisitor(SpatialIndex::ISpatialIndex *newIndex)
virtual void rewind() override
sets the stream pointer to the first entry, if possible.
static SpatialIndex::Region rectToRegion(const QgsRectangle &rect)
double y() const
Get the y value of the point.
QgsSpatialIndexData(const QgsSpatialIndexData &other)
void visitNode(const INode &n) override
QgisVisitor(QList< QgsFeatureId > &list)
void visitData(std::vector< const IData *> &v) override
QgsFeatureIteratorDataStream(const QgsFeatureIterator &fi)
constructor - needs to load all data to a vector for later access when bulk loading ...
#define FID_TO_NUMBER(fid)
Data of spatial index that may be implicitly shared.
void visitData(const IData &d) override
QgsSpatialIndex()
Constructor - creates R-tree.
void visitData(std::vector< const IData *> &v) override
Utility class for bulk loading of R-trees.
A class to represent a point.
QgsFeatureId id() const
Get the feature ID for this feature.
void visitData(const IData &d) override
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
double xMaximum() const
Get the x maximum value (right side of rectangle)
bool insertFeature(const QgsFeature &f)
Add feature to index.
~QgsSpatialIndex()
Destructor finalizes work with spatial index.
Custom visitor that adds found features to list.
double xMinimum() const
Get the x minimum value (left side of rectangle)
double yMaximum() const
Get the y maximum value (top side of rectangle)
static bool featureInfo(const QgsFeature &f, SpatialIndex::Region &r, QgsFeatureId &id)
virtual IData * getNext() override
returns a pointer to the next entry in the stream or 0 at the end of the stream.
~QgsFeatureIteratorDataStream()
double x() const
Get the x value of the point.
QAtomicInt refs() const
get reference count - just for debugging!