QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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
30 : d( new QgsSpatialIndexKDBushPrivate( source, feedback ) )
31{}
32
34QgsSpatialIndexKDBush::QgsSpatialIndexKDBush( QgsFeatureIterator &fi, const std::function<bool( const QgsFeature & )> &callback, QgsFeedback *feedback )
35 : d( new QgsSpatialIndexKDBushPrivate( fi, callback, feedback ) )
36{}
37
39
41 : d( new QgsSpatialIndexKDBushPrivate() )
42{}
43
45 : d( other.d )
46{
47 d->ref.ref();
48}
49
51{
52 if ( this != &other )
53 {
54 if ( !d->ref.deref() )
55 {
56 delete d;
57 }
58
59 d = other.d;
60 d->ref.ref();
61 }
62 return *this;
63}
64
66{
67 if ( !d->ref.deref() )
68 delete d;
69}
70
72{
73 return d->index->addFeature( id, point );
74}
75
77{
78 d->index->finalize();
79}
80
81QList<QgsSpatialIndexKDBushData> QgsSpatialIndexKDBush::within( const QgsPointXY &point, double radius ) const
82{
83 if ( !d->index->finalized )
84 return {};
85
86 QList<QgsSpatialIndexKDBushData> result;
87 d->index->within( point.x(), point.y(), radius, [&result]( const QgsSpatialIndexKDBushData &p ) { result << p; } );
88 return result;
89}
90
91void QgsSpatialIndexKDBush::within( const QgsPointXY &point, double radius, const std::function<void( QgsSpatialIndexKDBushData )> &visitor )
92{
93 if ( !d->index->finalized )
94 return;
95
96 d->index->within( point.x(), point.y(), radius, visitor );
97}
98
100{
101 return d->index->size();
102}
103
104QList<QgsSpatialIndexKDBushData> QgsSpatialIndexKDBush::intersects( const QgsRectangle &rectangle ) const
105{
106 if ( !d->index->finalized )
107 return {};
108
109 QList<QgsSpatialIndexKDBushData> result;
110 d->index->range( rectangle.xMinimum(), rectangle.yMinimum(), rectangle.xMaximum(), rectangle.yMaximum(), [&result]( const QgsSpatialIndexKDBushData &p ) { result << p; } );
111 return result;
112}
113
114void QgsSpatialIndexKDBush::intersects( const QgsRectangle &rectangle, const std::function<void( QgsSpatialIndexKDBushData )> &visitor ) const
115{
116 if ( !d->index->finalized )
117 return;
118
119 d->index->range( rectangle.xMinimum(), rectangle.yMinimum(), rectangle.xMaximum(), rectangle.yMaximum(), visitor );
120}
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:7485
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features