Skip to content

Commit c465c9f

Browse files
committedFeb 10, 2014
Fix #8434 (join by spatial location locks up QGIS)
By caching the features of the provider in the inner loop, there is a considerable speedup (compared to doing millions of queries)
1 parent db29ebc commit c465c9f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed
 

‎python/plugins/fTools/tools/doSpatialJoin.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ def compute(self, inName, joinName, outName, summary, sumList, keep, progressBar
168168
add = 85.00 / provider1.featureCount()
169169

170170
index = ftools_utils.createIndex(provider2)
171+
172+
# cache all features from provider2 to avoid huge number of feature requests in the inner loop
173+
mapP2 = {}
174+
for f in provider2.getFeatures():
175+
mapP2[f.id()] = QgsFeature(f)
176+
171177
fit1 = provider1.getFeatures()
172178
while fit1.nextFeature(inFeat):
173179
inGeom = inFeat.geometry()
@@ -192,8 +198,7 @@ def compute(self, inName, joinName, outName, summary, sumList, keep, progressBar
192198
if check == 0:
193199
count = 0
194200
for i in joinList:
195-
#tempGeom = i.geometry()
196-
provider2.getFeatures( QgsFeatureRequest().setFilterFid( int(i) ) ).nextFeature( inFeatB )
201+
inFeatB = mapP2[i] # cached feature from provider2
197202
if inGeom.intersects(inFeatB.geometry()):
198203
count = count + 1
199204
none = False

0 commit comments

Comments
 (0)
Please sign in to comment.