QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 {
37  d = other.d;
38  d->ref.ref();
39 }
40 
42 {
43  if ( !d->ref.deref() )
44  {
45  delete d;
46  }
47 
48  d = other.d;
49  d->ref.ref();
50  return *this;
51 }
52 
54 {
55  if ( !d->ref.deref() )
56  delete d;
57 }
58 
59 QList<QgsSpatialIndexKDBushData> QgsSpatialIndexKDBush::within( const QgsPointXY &point, double radius ) const
60 {
61  QList<QgsSpatialIndexKDBushData> result;
62  d->index->within( point.x(), point.y(), radius, [&result]( const QgsSpatialIndexKDBushData & p ) { result << p; } );
63  return result;
64 }
65 
66 void QgsSpatialIndexKDBush::within( const QgsPointXY &point, double radius, const std::function<void( QgsSpatialIndexKDBushData )> &visitor )
67 {
68  d->index->within( point.x(), point.y(), radius, visitor );
69 }
70 
72 {
73  return d->index->size();
74 }
75 
76 QList<QgsSpatialIndexKDBushData> QgsSpatialIndexKDBush::intersects( const QgsRectangle &rectangle ) const
77 {
78  QList<QgsSpatialIndexKDBushData> result;
79  d->index->range( rectangle.xMinimum(),
80  rectangle.yMinimum(),
81  rectangle.xMaximum(),
82  rectangle.yMaximum(), [&result]( const QgsSpatialIndexKDBushData & p ) { result << p; } );
83  return result;
84 }
85 
86 void QgsSpatialIndexKDBush::intersects( const QgsRectangle &rectangle, const std::function<void( QgsSpatialIndexKDBushData )> &visitor ) const
87 {
88  d->index->range( rectangle.xMinimum(),
89  rectangle.yMinimum(),
90  rectangle.xMaximum(),
91  rectangle.yMaximum(), visitor );
92 }
Wrapper for iterator of features from vector data provider or vector layer.
A rectangle specified with double values.
Definition: qgsrectangle.h:40
A container for data stored inside a QgsSpatialIndexKDBush index.
A very fast static spatial index for 2D points based on a flat KD-tree.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:171
double y
Definition: qgspointxy.h:48
A class to represent a 2D point.
Definition: qgspointxy.h:43
QList< QgsSpatialIndexKDBushData > within(const QgsPointXY &point, double radius) const
Returns the list of features which are within the given search radius of point.
QgsSpatialIndexKDBush & operator=(const QgsSpatialIndexKDBush &other)
Assignment operator.
Base class for feedback objects to be used for cancellation of something running in a worker thread...
Definition: qgsfeedback.h:44
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:176
double xMaximum() const
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:161
QList< QgsSpatialIndexKDBushData > intersects(const QgsRectangle &rectangle) const
Returns the list of features which fall within the specified rectangle.
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:586
double x
Definition: qgspointxy.h:47
An interface for objects which provide features via a getFeatures method.
qgssize size() const
Returns the size of the index, i.e.
QgsSpatialIndexKDBush(QgsFeatureIterator &fi, QgsFeedback *feedback=nullptr)
Constructor - creates KDBush index and bulk loads it with features from the iterator.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:166