Skip to content

Commit 6110931

Browse files
committed
Rename QgsSpatialIndex::insertFeature to ::addFeature, for consistency
with other classes And make QgsSpatialIndex a QgsFeatureSink
1 parent 63f597f commit 6110931

21 files changed

+139
-49
lines changed

python/core/auto_generated/qgsspatialindex.sip.in

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616

17-
class QgsSpatialIndex
17+
class QgsSpatialIndex : QgsFeatureSink
1818
{
1919
%Docstring
2020

@@ -75,18 +75,49 @@ Copy constructor
7575

7676

7777

78-
bool insertFeature( const QgsFeature &feature );
78+
bool insertFeature( const QgsFeature &feature ) /Deprecated/;
7979
%Docstring
8080
Adds a ``feature`` to the index.
81+
82+
.. deprecated:: Use addFeature() instead
83+
%End
84+
85+
virtual bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = 0 );
86+
87+
%Docstring
88+
Adds a ``feature`` to the index.
89+
90+
The ``flags`` argument is ignored.
91+
92+
.. versionadded:: 3.4
93+
%End
94+
95+
virtual bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = 0 );
96+
97+
%Docstring
98+
Adds a list of ``features`` to the index.
99+
100+
The ``flags`` argument is ignored.
101+
102+
.. seealso:: :py:func:`addFeature`
81103
%End
82104

83-
bool insertFeature( QgsFeatureId id, const QgsRectangle &bounds );
105+
bool insertFeature( QgsFeatureId id, const QgsRectangle &bounds ) /Deprecated/;
84106
%Docstring
85107
Add a feature ``id`` to the index with a specified bounding box.
86108

87109
:return: true if feature was successfully added to index.
88110

89-
.. versionadded:: 3.0
111+
.. deprecated:: Use addFeature() instead
112+
%End
113+
114+
bool addFeature( QgsFeatureId id, const QgsRectangle &bounds );
115+
%Docstring
116+
Add a feature ``id`` to the index with a specified bounding box.
117+
118+
:return: true if feature was successfully added to index.
119+
120+
.. versionadded:: 3.4
90121
%End
91122

92123
bool deleteFeature( const QgsFeature &feature );

python/plugins/processing/algs/qgis/DeleteDuplicateGeometries.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from qgis.core import (QgsFeatureRequest,
2929
QgsProcessingException,
3030
QgsFeatureSink,
31+
QgsSpatialIndex,
3132
QgsProcessingParameterFeatureSource,
3233
QgsProcessingParameterFeatureSink)
3334
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
@@ -71,11 +72,13 @@ def processAlgorithm(self, parameters, context, feedback):
7172
features = source.getFeatures(QgsFeatureRequest().setSubsetOfAttributes([]))
7273
total = 100.0 / source.featureCount() if source.featureCount() else 0
7374
geoms = dict()
75+
index = QgsSpatialIndex()
7476
for current, f in enumerate(features):
7577
if feedback.isCanceled():
7678
break
7779

7880
geoms[f.id()] = f.geometry()
81+
#index.insertFeature
7982
feedback.setProgress(int(current * total))
8083

8184
cleaned = dict(geoms)

python/plugins/processing/algs/qgis/PointsDisplacement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def searchRect(p):
116116

117117
other_features_within_radius = index.intersects(searchRect(point))
118118
if not other_features_within_radius:
119-
index.insertFeature(f)
119+
index.addFeature(f)
120120
group = [f]
121121
clustered_groups.append(group)
122122
group_index[f.id()] = len(clustered_groups) - 1

python/plugins/processing/algs/qgis/RandomPointsAlongLines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def processAlgorithm(self, parameters, context, feedback):
163163
f.setAttribute('id', nPoints)
164164
f.setGeometry(geom)
165165
sink.addFeature(f, QgsFeatureSink.FastInsert)
166-
index.insertFeature(f)
166+
index.addFeature(f)
167167
points[nPoints] = p
168168
nPoints += 1
169169
feedback.setProgress(int(nPoints * total))

python/plugins/processing/algs/qgis/RandomPointsExtent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def processAlgorithm(self, parameters, context, feedback):
142142
f.setAttribute('id', nPoints)
143143
f.setGeometry(geom)
144144
sink.addFeature(f, QgsFeatureSink.FastInsert)
145-
index.insertFeature(f)
145+
index.addFeature(f)
146146
points[nPoints] = p
147147
nPoints += 1
148148
feedback.setProgress(int(nPoints * total))

python/plugins/processing/algs/qgis/RandomPointsLayer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def processAlgorithm(self, parameters, context, feedback):
151151
f.setAttribute('id', nPoints)
152152
f.setGeometry(geom)
153153
sink.addFeature(f, QgsFeatureSink.FastInsert)
154-
index.insertFeature(f)
154+
index.addFeature(f)
155155
points[nPoints] = p
156156
nPoints += 1
157157
feedback.setProgress(int(nPoints * total))

python/plugins/processing/algs/qgis/RandomPointsPolygons.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def processAlgorithm(self, parameters, context, feedback):
197197
f.setAttribute('id', nPoints)
198198
f.setGeometry(geom)
199199
sink.addFeature(f, QgsFeatureSink.FastInsert)
200-
index.insertFeature(f)
200+
index.addFeature(f)
201201
points[nPoints] = p
202202
nPoints += 1
203203
feedback.setProgress(current_progress + int(nPoints * feature_total))

python/plugins/processing/algs/qgis/TopoColors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def compute_graph(features, feedback, create_id_graph=False, min_distance=0):
190190
if id_graph:
191191
id_graph.add_edge(f.id(), f2.id())
192192

193-
index.insertFeature(f)
193+
index.addFeature(f)
194194
i += 1
195195
feedback.setProgress(int(i * total))
196196

src/analysis/processing/qgsalgorithmsplitwithlines.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ QVariantMap QgsSplitWithLinesAlgorithm::processAlgorithm( const QVariantMap &par
118118
}
119119

120120
splitGeoms.insert( aSplitFeature.id(), aSplitFeature.geometry() );
121-
spatialIndex.insertFeature( aSplitFeature );
121+
spatialIndex.addFeature( aSplitFeature );
122122
}
123123

124124
QgsFeature outFeat;

src/analysis/processing/qgsoverlayutils.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ void QgsOverlayUtils::resolveOverlaps( const QgsFeatureSource &source, QgsFeatur
298298
std::unique_ptr< QgsGeometryEngine > g1engine;
299299

300300
geometries.insert( fid1, g1 );
301-
index.insertFeature( f );
301+
index.addFeature( f );
302302

303303
QgsRectangle bbox( f.geometry().boundingBox() );
304304
const QList<QgsFeatureId> ids = index.intersects( bbox );
@@ -335,7 +335,7 @@ void QgsOverlayUtils::resolveOverlaps( const QgsFeatureSource &source, QgsFeatur
335335
QgsFeature fx( newFid );
336336
fx.setGeometry( geomIntersection );
337337

338-
index.insertFeature( fx );
338+
index.addFeature( fx );
339339

340340
// figure out which feature IDs belong to this intersection. Some of the IDs can be of the newly
341341
// created geometries - in such case we need to retrieve original IDs
@@ -365,7 +365,7 @@ void QgsOverlayUtils::resolveOverlaps( const QgsFeatureSource &source, QgsFeatur
365365

366366
QgsFeature f1x( fid1 );
367367
f1x.setGeometry( g12 );
368-
index.insertFeature( f1x );
368+
index.addFeature( f1x );
369369
}
370370

371371
//
@@ -386,7 +386,7 @@ void QgsOverlayUtils::resolveOverlaps( const QgsFeatureSource &source, QgsFeatur
386386

387387
QgsFeature f2x( fid2 );
388388
f2x.setGeometry( g21 );
389-
index.insertFeature( f2x );
389+
index.addFeature( f2x );
390390
}
391391

392392
// update our temporary copy of the geometry to what is left from it

0 commit comments

Comments
 (0)