24 #include "SpatialIndex.h"
42 mList.append( d.getIdentifier() );
45 void visitData( std::vector<const IData*>& v )
override
56 : mNewIndex( newIndex ) {}
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;
97 RTree::Data* ret = mNextData;
104 virtual bool hasNext()
override {
return mNextData != 0; }
107 virtual uint32_t
size()
override { Q_ASSERT( 0 &&
"not available" );
return 0; }
110 virtual void rewind()
override { Q_ASSERT( 0 &&
"not available" ); }
116 SpatialIndex::Region r;
118 while ( mFi.nextFeature( f ) )
122 mNextData =
new RTree::Data( 0, 0, r,
id );
130 RTree::Data* mNextData;
155 double low[] = { DBL_MIN, DBL_MIN };
156 double high[] = { DBL_MAX, DBL_MAX };
157 SpatialIndex::Region query( low, high, 2 );
159 other.
mRTree->intersectsWithQuery( query, visitor );
171 mStorage = StorageManager::createNewMemoryStorageManager();
174 double fillFactor = 0.7;
175 unsigned long indexCapacity = 10;
176 unsigned long leafCapacity = 10;
177 unsigned long dimension = 2;
178 RTree::RTreeVariant variant = RTree::RV_RSTAR;
181 SpatialIndex::id_type indexId;
184 mRTree = RTree::createAndBulkLoadNewRTree( RTree::BLM_STR, *inputStream, *mStorage, fillFactor, indexCapacity,
185 leafCapacity, dimension, variant, indexId );
187 mRTree = RTree::createNewRTree( *mStorage, fillFactor, indexCapacity,
188 leafCapacity, dimension, variant, indexId );
222 if (
this != &other )
229 double pt1[2], pt2[2];
234 return Region( pt1, pt2, 2 );
263 catch ( Tools::Exception &e )
268 catch (
const std::exception &e )
275 QgsDebugMsg(
"unknown spatial index exception caught" );
299 d->mRTree->intersectsWithQuery( r, visitor );
314 d->mRTree->nearestNeighborQuery( neighbors, p, visitor );
QgsFeatureId id() const
Get the feature ID for this feature.
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.
void initTree(IDataStream *inputStream=0)
QList< QgsFeatureId > intersects(const QgsRectangle &rect) const
Returns features that intersect the specified rectangle.
bool deleteFeature(const QgsFeature &f)
Remove feature from index.
double yMaximum() const
Get the y maximum value (top side of rectangle)
QgsSpatialIndexData(const QgsFeatureIterator &fi)
void visitData(std::vector< const IData * > &v) override
static SpatialIndex::Region rectToRegion(const QgsRectangle &rect)
void visitNode(const INode &n) override
A geometry is the spatial representation of a feature.
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.
void visitData(std::vector< const IData * > &v) override
double x() const
Get the x value of the point.
QgsSpatialIndexData(const QgsSpatialIndexData &other)
void visitNode(const INode &n) override
QgisVisitor(QList< QgsFeatureId > &list)
QgsFeatureIteratorDataStream(const QgsFeatureIterator &fi)
constructor - needs to load all data to a vector for later access when bulk loading ...
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)
Data of spatial index that may be implicitly shared.
void visitData(const IData &d) override
QgsSpatialIndex()
Constructor - creates R-tree.
Utility class for bulk loading of R-trees.
A class to represent a point.
QList< QgsFeatureId > nearestNeighbor(const QgsPoint &point, int neighbors) const
Returns nearest neighbors (their count is specified by second parameter)
QAtomicInt refs() const
get reference count - just for debugging!
void visitData(const IData &d) override
bool insertFeature(const QgsFeature &f)
Add feature to index.
~QgsSpatialIndex()
Destructor finalizes work with spatial index.
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
double y() const
Get the y value of the point.
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 xMinimum() const
Get the x minimum value (left side of rectangle)