QGIS API Documentation 3.99.0-Master (e9821da5c6b)
Loading...
Searching...
No Matches
qgsspatialindexkdbush.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsspatialindexkdbush.cpp
3 -------------------
4 begin : July 2018
5 copyright : (C) 2018 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19
20#include "qgsfeatureiterator.h"
21#include "qgsfeaturesource.h"
22#include "qgsfeedback.h"
24
26 : d( new QgsSpatialIndexKDBushPrivate( fi, feedback ) )
27{
28
29}
30
32 : d( new QgsSpatialIndexKDBushPrivate( source, feedback ) )
33{
34}
35
37QgsSpatialIndexKDBush::QgsSpatialIndexKDBush( QgsFeatureIterator &fi, const std::function<bool ( const QgsFeature & )> &callback, QgsFeedback *feedback )
38 : d( new QgsSpatialIndexKDBushPrivate( fi, callback, feedback ) )
39{
40}
41
43
45 : d( new QgsSpatialIndexKDBushPrivate() )
46{
47}
48
50{
51 d->ref.ref();
52}
53
55{
56 if ( this != &other )
57 {
58 if ( !d->ref.deref() )
59 {
60 delete d;
61 }
62
63 d = other.d;
64 d->ref.ref();
65 }
66 return *this;
67}
68
70{
71 if ( !d->ref.deref() )
72 delete d;
73}
74
76{
77 return d->index->addFeature( id, point );
78}
79
81{
82 d->index->finalize();
83}
84
85QList<QgsSpatialIndexKDBushData> QgsSpatialIndexKDBush::within( const QgsPointXY &point, double radius ) const
86{
87 if ( !d->index->finalized )
88 return {};
89
90 QList<QgsSpatialIndexKDBushData> result;
91 d->index->within( point.x(), point.y(), radius, [&result]( const QgsSpatialIndexKDBushData & p ) { result << p; } );
92 return result;
93}
94
95void QgsSpatialIndexKDBush::within( const QgsPointXY &point, double radius, const std::function<void( QgsSpatialIndexKDBushData )> &visitor )
96{
97 if ( !d->index->finalized )
98 return;
99
100 d->index->within( point.x(), point.y(), radius, visitor );
101}
102
104{
105 return d->index->size();
106}
107
108QList<QgsSpatialIndexKDBushData> QgsSpatialIndexKDBush::intersects( const QgsRectangle &rectangle ) const
109{
110 if ( !d->index->finalized )
111 return {};
112
113 QList<QgsSpatialIndexKDBushData> result;
114 d->index->range( rectangle.xMinimum(),
115 rectangle.yMinimum(),
116 rectangle.xMaximum(),
117 rectangle.yMaximum(), [&result]( const QgsSpatialIndexKDBushData & p ) { result << p; } );
118 return result;
119}
120
121void QgsSpatialIndexKDBush::intersects( const QgsRectangle &rectangle, const std::function<void( QgsSpatialIndexKDBushData )> &visitor ) const
122{
123 if ( !d->index->finalized )
124 return;
125
126 d->index->range( rectangle.xMinimum(),
127 rectangle.yMinimum(),
128 rectangle.xMaximum(),
129 rectangle.yMaximum(), visitor );
130}
Wrapper for iterator of features from vector data provider or vector layer.
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:60
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Represents a 2D point.
Definition qgspointxy.h:62
double y
Definition qgspointxy.h:66
double x
Definition qgspointxy.h:65
A rectangle specified with double values.
double xMinimum
double yMinimum
double xMaximum
double yMaximum
A container for data stored inside a QgsSpatialIndexKDBush index.
QgsSpatialIndexKDBush()
Constructs an empty index.
void finalize()
Finalizes the index after manually adding features.
QgsSpatialIndexKDBush(QgsFeatureIterator &fi, QgsFeedback *feedback=nullptr)
Constructor - creates KDBush index and bulk loads it with features from the iterator.
qgssize size() const
Returns the size of the index, i.e.
QList< QgsSpatialIndexKDBushData > intersects(const QgsRectangle &rectangle) const
Returns the list of features which fall within the specified rectangle.
bool addFeature(QgsFeatureId id, const QgsPointXY &point)
Adds a single feature to the index.
QgsSpatialIndexKDBush & operator=(const QgsSpatialIndexKDBush &other)
QList< QgsSpatialIndexKDBushData > within(const QgsPointXY &point, double radius) const
Returns the list of features which are within the given search radius of point.
unsigned long long qgssize
Qgssize is used instead of size_t, because size_t is stdlib type, unknown by SIP, and it would be har...
Definition qgis.h:7447
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features