Skip to content
Permalink
Browse files
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)
  • Loading branch information
wonder-sk committed Feb 10, 2014
1 parent db29ebc commit c465c9f03d5e190e0aa1491943bdadb18716587e
Showing with 7 additions and 2 deletions.
  1. +7 −2 python/plugins/fTools/tools/doSpatialJoin.py
@@ -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()
@@ -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

0 comments on commit c465c9f

Please sign in to comment.