QGIS API Documentation  2.99.0-Master (b698612)
qgsspatialindex.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsspatialindex.h - wrapper class for spatial index library
3  ----------------------
4  begin : December 2006
5  copyright : (C) 2006 by Martin Dobias
6  email : wonder.sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSSPATIALINDEX_H
17 #define QGSSPATIALINDEX_H
18 
19 
20 #include "qgis_sip.h"
21 
22 // forward declaration
23 namespace SpatialIndex SIP_SKIP
24 {
25  class IStorageManager;
26  class ISpatialIndex;
27  class Region;
28  class Point;
29 
30  namespace StorageManager
31  {
32  class IBuffer;
33  }
34 }
35 
36 class QgsFeature;
37 class QgsRectangle;
38 class QgsPointXY;
39 
40 #include "qgis_core.h"
41 #include "qgis_sip.h"
42 #include <QList>
43 #include <QSharedDataPointer>
44 
45 #include "qgsfeature.h"
46 
48 class QgsFeatureIterator;
49 class QgsFeatureSource;
50 
54 class CORE_EXPORT QgsSpatialIndex
55 {
56 
57  public:
58 
59  /* creation of spatial index */
60 
63 
69  explicit QgsSpatialIndex( const QgsFeatureIterator &fi );
70 
77  explicit QgsSpatialIndex( const QgsFeatureSource &source );
78 
80  QgsSpatialIndex( const QgsSpatialIndex &other );
81 
83  ~QgsSpatialIndex();
84 
86  QgsSpatialIndex &operator=( const QgsSpatialIndex &other );
87 
88  /* operations */
89 
91  bool insertFeature( const QgsFeature &f );
92 
98  bool insertFeature( QgsFeatureId id, const QgsRectangle &bounds );
99 
101  bool deleteFeature( const QgsFeature &f );
102 
103 
104  /* queries */
105 
107  QList<QgsFeatureId> intersects( const QgsRectangle &rect ) const;
108 
110  QList<QgsFeatureId> nearestNeighbor( const QgsPointXY &point, int neighbors ) const;
111 
112  /* debugging */
113 
115  QAtomicInt SIP_PYALTERNATIVETYPE( int ) refs() const;
116 
117  private:
118 
119  static SpatialIndex::Region rectToRegion( const QgsRectangle &rect );
120 
128  static bool featureInfo( const QgsFeature &f, SpatialIndex::Region &r, QgsFeatureId &id ) SIP_SKIP;
129 
138  static bool featureInfo( const QgsFeature &f, QgsRectangle &rect, QgsFeatureId &id );
139 
140  friend class QgsFeatureIteratorDataStream; // for access to featureInfo()
141 
142  private:
143 
144  QSharedDataPointer<QgsSpatialIndexData> d;
145 
146 };
147 
148 #endif
149 
Wrapper for iterator of features from vector data provider or vector layer.
A rectangle specified with double values.
Definition: qgsrectangle.h:38
A class to represent a 2D point.
Definition: qgspointxy.h:42
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:61
#define SIP_SKIP
Definition: qgis_sip.h:107
Data of spatial index that may be implicitly shared.
Utility class for bulk loading of R-trees.
An interface for objects which provide features via a getFeatures method.
qint64 QgsFeatureId
Definition: qgsfeature.h:37
#define SIP_PYALTERNATIVETYPE(type)
Definition: qgis_sip.h:117