Skip to content

Commit

Permalink
Fix #8434 (join by spatial location locks up QGIS)
Browse files Browse the repository at this point in the history
By caching the features of the provider in the inner loop, there is
a considerable speedup (compared to doing millions of queries)
  • Loading branch information
wonder-sk committed Feb 10, 2014
1 parent db29ebc commit c465c9f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions python/plugins/fTools/tools/doSpatialJoin.py
Expand Up @@ -168,6 +168,12 @@ def compute(self, inName, joinName, outName, summary, sumList, keep, progressBar
add = 85.00 / provider1.featureCount()

index = ftools_utils.createIndex(provider2)

# cache all features from provider2 to avoid huge number of feature requests in the inner loop
mapP2 = {}
for f in provider2.getFeatures():
mapP2[f.id()] = QgsFeature(f)

fit1 = provider1.getFeatures()
while fit1.nextFeature(inFeat):
inGeom = inFeat.geometry()
Expand All @@ -192,8 +198,7 @@ def compute(self, inName, joinName, outName, summary, sumList, keep, progressBar
if check == 0:
count = 0
for i in joinList:
#tempGeom = i.geometry()
provider2.getFeatures( QgsFeatureRequest().setFilterFid( int(i) ) ).nextFeature( inFeatB )
inFeatB = mapP2[i] # cached feature from provider2
if inGeom.intersects(inFeatB.geometry()):
count = count + 1
none = False
Expand Down

0 comments on commit c465c9f

Please sign in to comment.