QGIS API Documentation 3.39.0-Master (3aed037ce22)
Loading...
Searching...
No Matches
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
23namespace 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
36class QgsFeedback;
37class QgsFeature;
38class QgsRectangle;
39class QgsPointXY;
40
41#include "qgis_core.h"
42#include "qgsfeaturesink.h"
43#include <QList>
44#include <QSharedDataPointer>
45
46#include "qgsfeature.h"
47
48class QgsSpatialIndexData;
51
67class CORE_EXPORT QgsSpatialIndex : public QgsFeatureSink
68{
69
70 public:
71
72 /* creation of spatial index */
73
75 enum Flag SIP_ENUM_BASETYPE( IntFlag )
76 {
77 FlagStoreFeatureGeometries = 1 << 0,
78 };
79 Q_DECLARE_FLAGS( Flags, Flag )
80
81
85
95 explicit QgsSpatialIndex( const QgsFeatureIterator &fi, QgsFeedback *feedback = nullptr, QgsSpatialIndex::Flags flags = QgsSpatialIndex::Flags() );
96
97#ifndef SIP_RUN
98
110 explicit QgsSpatialIndex( const QgsFeatureIterator &fi, const std::function< bool( const QgsFeature & ) > &callback, QgsSpatialIndex::Flags flags = QgsSpatialIndex::Flags() );
111#endif
112
123 explicit QgsSpatialIndex( const QgsFeatureSource &source, QgsFeedback *feedback = nullptr, QgsSpatialIndex::Flags flags = QgsSpatialIndex::Flags() );
124
125 QgsSpatialIndex( const QgsSpatialIndex &other );
126
128 ~QgsSpatialIndex() override;
129
130 QgsSpatialIndex &operator=( const QgsSpatialIndex &other );
131
132 /* operations */
133
138 Q_DECL_DEPRECATED bool insertFeature( const QgsFeature &feature ) SIP_DEPRECATED;
139
147 bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
148
156 bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
157
163 Q_DECL_DEPRECATED bool insertFeature( QgsFeatureId id, const QgsRectangle &bounds ) SIP_DEPRECATED;
164
170 bool addFeature( QgsFeatureId id, const QgsRectangle &bounds );
171
175 bool deleteFeature( const QgsFeature &feature );
176
182 bool deleteFeature( QgsFeatureId id, const QgsRectangle &bounds );
183
184 /* queries */
185
193 QList<QgsFeatureId> intersects( const QgsRectangle &rectangle ) const;
194
211 QList<QgsFeatureId> nearestNeighbor( const QgsPointXY &point, int neighbors = 1, double maxDistance = 0 ) const;
212
231 QList<QgsFeatureId> nearestNeighbor( const QgsGeometry &geometry, int neighbors = 1, double maxDistance = 0 ) const;
232
233#ifndef SIP_RUN
234
242 QgsGeometry geometry( QgsFeatureId id ) const;
243
244#else
245
255 SIP_PYOBJECT geometry( QgsFeatureId id ) const SIP_TYPEHINT( QgsGeometry );
256 % MethodCode
257 std::unique_ptr< QgsGeometry > g = std::make_unique< QgsGeometry >( sipCpp->geometry( a0 ) );
258 if ( g->isNull() )
259 {
260 PyErr_SetString( PyExc_KeyError, QStringLiteral( "No geometry with feature id %1 exists in the index." ).arg( a0 ).toUtf8().constData() );
261 sipIsErr = 1;
262 }
263 else
264 {
265 sipRes = sipConvertFromType( g.release(), sipType_QgsGeometry, Py_None );
266 }
267 % End
268#endif
269
270 /* debugging */
271
273 QAtomicInt SIP_PYALTERNATIVETYPE( int ) refs() const;
274
275 private:
276
285 static bool featureInfo( const QgsFeature &f, SpatialIndex::Region &r, QgsFeatureId &id ) SIP_SKIP;
286
295 static bool featureInfo( const QgsFeature &f, QgsRectangle &rect, QgsFeatureId &id );
296
297 friend class QgsFeatureIteratorDataStream; // for access to featureInfo()
298
299 private:
300
301 QSharedDataPointer<QgsSpatialIndexData> d;
302
303};
304
306
307#endif //QGSSPATIALINDEX_H
Wrapper for iterator of features from vector data provider or vector layer.
An interface for objects which accept features via addFeature(s) methods.
virtual bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags())
Adds a single feature to the sink.
virtual bool addFeatures(QgsFeatureList &features, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags())=0
Adds a list of features to the sink.
QFlags< Flag > Flags
An interface for objects which provide features via a getFeatures method.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
A geometry is the spatial representation of a feature.
A class to represent a 2D point.
Definition qgspointxy.h:60
A rectangle specified with double values.
A spatial index for QgsFeature objects.
Flag
Flags controlling index behavior.
QFlags< Flag > Flags
QgsSpatialIndex(const QgsFeatureIterator &fi, const std::function< bool(const QgsFeature &) > &callback, QgsSpatialIndex::Flags flags=QgsSpatialIndex::Flags())
Constructor - creates R-tree and bulk loads it with features from the iterator.
#define SIP_TYPEHINT(type)
Definition qgis_sip.h:232
#define SIP_PYALTERNATIVETYPE(type)
Definition qgis_sip.h:141
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:278
#define SIP_SKIP
Definition qgis_sip.h:126
QList< QgsFeature > QgsFeatureList
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)