24 #include "SpatialIndex.h"
26 using namespace SpatialIndex;
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;
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;
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 );
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 );
261 catch ( Tools::Exception &e )
266 catch (
const std::exception &e )
273 QgsDebugMsg(
"unknown spatial index exception caught" );
297 d->mRTree->intersectsWithQuery( r, visitor );
312 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
static SpatialIndex::Region rectToRegion(QgsRectangle rect)
SpatialIndex::ISpatialIndex * mRTree
R-tree containing spatial index.
void initTree(IDataStream *inputStream=0)
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
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.
QList< QgsFeatureId > intersects(QgsRectangle rect) const
returns features that intersect the specified rectangle
void visitData(std::vector< const IData * > &v) override
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.
QList< QgsFeatureId > nearestNeighbor(QgsPoint point, int neighbors) const
returns nearest neighbors (their count is specified by second parameter)
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.
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.
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)