QGIS API Documentation  3.0.2-Girona (307d082)
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 QgsFeedback;
37 class QgsFeature;
38 class QgsRectangle;
39 class QgsPointXY;
40 
41 #include "qgis_core.h"
42 #include "qgis_sip.h"
43 #include <QList>
44 #include <QSharedDataPointer>
45 
46 #include "qgsfeature.h"
47 
49 class QgsFeatureIterator;
50 class QgsFeatureSource;
51 
64 class CORE_EXPORT QgsSpatialIndex
65 {
66 
67  public:
68 
69  /* creation of spatial index */
70 
75 
86  explicit QgsSpatialIndex( const QgsFeatureIterator &fi, QgsFeedback *feedback = nullptr );
87 
99  explicit QgsSpatialIndex( const QgsFeatureSource &source, QgsFeedback *feedback = nullptr );
100 
102  QgsSpatialIndex( const QgsSpatialIndex &other );
103 
105  ~QgsSpatialIndex();
106 
108  QgsSpatialIndex &operator=( const QgsSpatialIndex &other );
109 
110  /* operations */
111 
115  bool insertFeature( const QgsFeature &feature );
116 
122  bool insertFeature( QgsFeatureId id, const QgsRectangle &bounds );
123 
127  bool deleteFeature( const QgsFeature &feature );
128 
129 
130  /* queries */
131 
139  QList<QgsFeatureId> intersects( const QgsRectangle &rectangle ) const;
140 
148  QList<QgsFeatureId> nearestNeighbor( const QgsPointXY &point, int neighbors ) const;
149 
150  /* debugging */
151 
153  QAtomicInt SIP_PYALTERNATIVETYPE( int ) refs() const;
154 
155  private:
156 
157  static SpatialIndex::Region rectToRegion( const QgsRectangle &rect );
158 
167  static bool featureInfo( const QgsFeature &f, SpatialIndex::Region &r, QgsFeatureId &id ) SIP_SKIP;
168 
178  static bool featureInfo( const QgsFeature &f, QgsRectangle &rect, QgsFeatureId &id );
179 
180  friend class QgsFeatureIteratorDataStream; // for access to featureInfo()
181 
182  private:
183 
184  QSharedDataPointer<QgsSpatialIndexData> d;
185 
186 };
187 
188 #endif
189 
Wrapper for iterator of features from vector data provider or vector layer.
A rectangle specified with double values.
Definition: qgsrectangle.h:39
A class to represent a 2D point.
Definition: qgspointxy.h:43
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:62
Base class for feedback objects to be used for cancelation of something running in a worker thread...
Definition: qgsfeedback.h:44
#define SIP_SKIP
Definition: qgis_sip.h:119
Data of spatial index that may be implicitly shared.
Utility class for bulk loading of R-trees.
A spatial index for QgsFeature objects.
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:129