QGIS API Documentation
4.3.0-Master (9dce731a7a1)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
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
20
#include "
qgsfeatureiterator.h
"
21
#include "
qgsfeaturesource.h
"
22
#include "
qgsfeedback.h
"
23
#include "
qgsspatialindexkdbush_p.h
"
24
25
QgsSpatialIndexKDBush::QgsSpatialIndexKDBush
(
QgsFeatureIterator
&fi,
QgsFeedback
*feedback )
26
: d( new QgsSpatialIndexKDBushPrivate( fi, feedback ) )
27
{}
28
29
QgsSpatialIndexKDBush::QgsSpatialIndexKDBush
(
const
QgsFeatureSource
&source,
QgsFeedback
*feedback )
30
: d( new QgsSpatialIndexKDBushPrivate( source, feedback ) )
31
{}
32
34
QgsSpatialIndexKDBush::QgsSpatialIndexKDBush
(
QgsFeatureIterator
&fi,
const
std::function<
bool
(
const
QgsFeature
& )> &callback,
QgsFeedback
*feedback )
35
: d( new QgsSpatialIndexKDBushPrivate( fi, callback, feedback ) )
36
{}
37
39
40
QgsSpatialIndexKDBush::QgsSpatialIndexKDBush
()
41
: d( new QgsSpatialIndexKDBushPrivate() )
42
{}
43
44
QgsSpatialIndexKDBush::QgsSpatialIndexKDBush
(
const
QgsSpatialIndexKDBush
&other )
45
: d( other.d )
46
{
47
d->ref.ref();
48
}
49
50
QgsSpatialIndexKDBush
&
QgsSpatialIndexKDBush::operator=
(
const
QgsSpatialIndexKDBush
&other )
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
65
QgsSpatialIndexKDBush::~QgsSpatialIndexKDBush
()
66
{
67
if
( !d->ref.deref() )
68
delete
d;
69
}
70
71
bool
QgsSpatialIndexKDBush::addFeature
(
QgsFeatureId
id
,
const
QgsPointXY
&point )
72
{
73
return
d->index->
addFeature
(
id
, point );
74
}
75
76
void
QgsSpatialIndexKDBush::finalize
()
77
{
78
d->index->finalize();
79
}
80
81
QList<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
91
void
QgsSpatialIndexKDBush::within
(
const
QgsPointXY
&point,
double
radius,
const
std::function<
void
(
const
QgsSpatialIndexKDBushData
& )> &visitor )
const
92
{
93
if
( !d->index->finalized )
94
return
;
95
96
d->index->within( point.
x
(), point.
y
(), radius, visitor );
97
}
98
99
qgssize
QgsSpatialIndexKDBush::size
()
const
100
{
101
return
d->index->size();
102
}
103
104
QList<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
114
void
QgsSpatialIndexKDBush::intersects
(
const
QgsRectangle
&rectangle,
const
std::function<
void
(
const
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
}
QgsFeatureIterator
Wrapper for iterator of features from vector data provider or vector layer.
Definition
qgsfeatureiterator.h:284
QgsFeatureSource
An interface for objects which provide features via a getFeatures method.
Definition
qgsfeaturesource.h:37
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition
qgsfeature.h:60
QgsFeedback
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition
qgsfeedback.h:44
QgsPointXY
Represents a 2D point.
Definition
qgspointxy.h:62
QgsPointXY::y
double y
Definition
qgspointxy.h:66
QgsPointXY::x
double x
Definition
qgspointxy.h:65
QgsRectangle
A rectangle specified with double values.
Definition
qgsrectangle.h:47
QgsRectangle::xMinimum
double xMinimum
Definition
qgsrectangle.h:50
QgsRectangle::yMinimum
double yMinimum
Definition
qgsrectangle.h:52
QgsRectangle::xMaximum
double xMaximum
Definition
qgsrectangle.h:51
QgsRectangle::yMaximum
double yMaximum
Definition
qgsrectangle.h:53
QgsSpatialIndexKDBushData
A container for data stored inside a QgsSpatialIndexKDBush index.
Definition
qgsspatialindexkdbushdata.h:33
QgsSpatialIndexKDBush::QgsSpatialIndexKDBush
QgsSpatialIndexKDBush()
Constructs an empty index.
Definition
qgsspatialindexkdbush.cpp:40
QgsSpatialIndexKDBush::~QgsSpatialIndexKDBush
~QgsSpatialIndexKDBush()
Definition
qgsspatialindexkdbush.cpp:65
QgsSpatialIndexKDBush::finalize
void finalize()
Finalizes the index after manually adding features.
Definition
qgsspatialindexkdbush.cpp:76
QgsSpatialIndexKDBush::QgsSpatialIndexKDBush
QgsSpatialIndexKDBush(QgsFeatureIterator &fi, QgsFeedback *feedback=nullptr)
Constructor - creates KDBush index and bulk loads it with features from the iterator.
Definition
qgsspatialindexkdbush.cpp:25
QgsSpatialIndexKDBush::size
qgssize size() const
Returns the size of the index, i.e.
Definition
qgsspatialindexkdbush.cpp:99
QgsSpatialIndexKDBush::intersects
QList< QgsSpatialIndexKDBushData > intersects(const QgsRectangle &rectangle) const
Returns the list of features which fall within the specified rectangle.
Definition
qgsspatialindexkdbush.cpp:104
QgsSpatialIndexKDBush::addFeature
bool addFeature(QgsFeatureId id, const QgsPointXY &point)
Adds a single feature to the index.
Definition
qgsspatialindexkdbush.cpp:71
QgsSpatialIndexKDBush::operator=
QgsSpatialIndexKDBush & operator=(const QgsSpatialIndexKDBush &other)
Definition
qgsspatialindexkdbush.cpp:50
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:81
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:8400
QgsFeatureId
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition
qgsfeatureid.h:32
qgsfeatureiterator.h
qgsfeaturesource.h
qgsfeedback.h
qgsspatialindexkdbush.h
qgsspatialindexkdbush_p.h
Generated on
for QGIS API Documentation by
1.17.0