QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
18 #include "qgsspatialindexkdbush.h"
19 #include "qgsfeatureiterator.h"
20 #include "qgsfeedback.h"
21 #include "qgsfeaturesource.h"
23 
25  : d( new QgsSpatialIndexKDBushPrivate( fi, feedback ) )
26 {
27 
28 }
29 
31  : d( new QgsSpatialIndexKDBushPrivate( source, feedback ) )
32 {
33 }
34 
36 QgsSpatialIndexKDBush::QgsSpatialIndexKDBush( QgsFeatureIterator &fi, const std::function<bool ( const QgsFeature & )> &callback, QgsFeedback *feedback )
37  : d( new QgsSpatialIndexKDBushPrivate( fi, callback, feedback ) )
38 {
39 }
41 
43 {
44  d->ref.ref();
45 }
46 
48 {
49  if ( this != &other )
50  {
51  if ( !d->ref.deref() )
52  {
53  delete d;
54  }
55 
56  d = other.d;
57  d->ref.ref();
58  }
59  return *this;
60 }
61 
63 {
64  if ( !d->ref.deref() )
65  delete d;
66 }
67 
68 QList<QgsSpatialIndexKDBushData> QgsSpatialIndexKDBush::within( const QgsPointXY &point, double radius ) const
69 {
70  QList<QgsSpatialIndexKDBushData> result;
71  d->index->within( point.x(), point.y(), radius, [&result]( const QgsSpatialIndexKDBushData & p ) { result << p; } );
72  return result;
73 }
74 
75 void QgsSpatialIndexKDBush::within( const QgsPointXY &point, double radius, const std::function<void( QgsSpatialIndexKDBushData )> &visitor )
76 {
77  d->index->within( point.x(), point.y(), radius, visitor );
78 }
79 
81 {
82  return d->index->size();
83 }
84 
85 QList<QgsSpatialIndexKDBushData> QgsSpatialIndexKDBush::intersects( const QgsRectangle &rectangle ) const
86 {
87  QList<QgsSpatialIndexKDBushData> result;
88  d->index->range( rectangle.xMinimum(),
89  rectangle.yMinimum(),
90  rectangle.xMaximum(),
91  rectangle.yMaximum(), [&result]( const QgsSpatialIndexKDBushData & p ) { result << p; } );
92  return result;
93 }
94 
95 void QgsSpatialIndexKDBush::intersects( const QgsRectangle &rectangle, const std::function<void( QgsSpatialIndexKDBushData )> &visitor ) const
96 {
97  d->index->range( rectangle.xMinimum(),
98  rectangle.yMinimum(),
99  rectangle.xMaximum(),
100  rectangle.yMaximum(), visitor );
101 }
qgsspatialindexkdbush_p.h
QgsPointXY::y
double y
Definition: qgspointxy.h:63
qgsfeatureiterator.h
QgsRectangle::yMinimum
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:198
QgsFeatureSource
An interface for objects which provide features via a getFeatures method.
Definition: qgsfeaturesource.h:37
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsRectangle::xMaximum
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:183
QgsSpatialIndexKDBush::intersects
QList< QgsSpatialIndexKDBushData > intersects(const QgsRectangle &rectangle) const
Returns the list of features which fall within the specified rectangle.
Definition: qgsspatialindexkdbush.cpp:85
qgsspatialindexkdbush.h
QgsSpatialIndexKDBush::size
qgssize size() const
Returns the size of the index, i.e.
Definition: qgsspatialindexkdbush.cpp:80
QgsFeedback
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:44
QgsSpatialIndexKDBush::QgsSpatialIndexKDBush
QgsSpatialIndexKDBush(QgsFeatureIterator &fi, QgsFeedback *feedback=nullptr)
Constructor - creates KDBush index and bulk loads it with features from the iterator.
Definition: qgsspatialindexkdbush.cpp:24
QgsSpatialIndexKDBush::~QgsSpatialIndexKDBush
~QgsSpatialIndexKDBush()
Definition: qgsspatialindexkdbush.cpp:62
qgsfeaturesource.h
QgsRectangle::xMinimum
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:188
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:58
QgsRectangle::yMaximum
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:193
QgsPointXY::x
double x
Definition: qgspointxy.h:62
QgsSpatialIndexKDBush::operator=
QgsSpatialIndexKDBush & operator=(const QgsSpatialIndexKDBush &other)
Assignment operator.
Definition: qgsspatialindexkdbush.cpp:47
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsFeatureIterator
Wrapper for iterator of features from vector data provider or vector layer.
Definition: qgsfeatureiterator.h:289
qgsfeedback.h
QgsSpatialIndexKDBush
A very fast static spatial index for 2D points based on a flat KD-tree.
Definition: qgsspatialindexkdbush.h:54
QgsSpatialIndexKDBushData
A container for data stored inside a QgsSpatialIndexKDBush index.
Definition: qgsspatialindexkdbushdata.h:32
qgssize
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:2791
QgsSpatialIndexKDBush::within
QList< QgsSpatialIndexKDBushData > within(const QgsPointXY &point, double radius) const
Returns the list of features which are within the given search radius of point.
Definition: qgsspatialindexkdbush.cpp:68