Skip to content
Permalink
Browse files
Update to select by location tool: should run faster for large layers…
…, and requires less memory. Should also fix #1669

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13205 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
cfarmer committed Mar 30, 2010
1 parent 08573c6 commit 6e48297fd68f9d70633c91101bb22e48ad45ef3e
Showing with 17 additions and 11 deletions.
  1. +17 −11 python/plugins/fTools/tools/doSelectByLocation.py
@@ -55,23 +55,29 @@ def compute(self, inPoly, inPts, modify):
inputLayer = ftools_utils.getVectorLayerByName(inPoly)
selectLayer = ftools_utils.getVectorLayerByName(inPts)
inputProvider = inputLayer.dataProvider()
allAttrs = inputProvider.attributeIndexes()
inputProvider.select(allAttrs)
selectProvider = selectLayer.dataProvider()
allAttrs = selectProvider.attributeIndexes()
selectProvider.select(allAttrs)
feat = QgsFeature()
infeat = QgsFeature()
geom = QgsGeometry()
selectedSet = []
selectProvider.nextFeature(feat)
geomLayer = QgsGeometry(feat.geometry())

self.progressBar.setMaximum( inputProvider.featureCount() + selectProvider.featureCount() )

index = ftools_utils.createIndex(inputProvider)
#selectProvider.nextFeature(feat)
#geomLayer = QgsGeometry(feat.geometry())
self.progressBar.setMaximum(selectProvider.featureCount())
while selectProvider.nextFeature(feat):
geomLayer = geomLayer.combine(QgsGeometry(feat.geometry()))
self.progressBar.setValue( self.progressBar.value() + 1 )
while inputProvider.nextFeature(feat):
geom = QgsGeometry(feat.geometry())
if geom.intersects(geomLayer):
selectedSet.append(feat.id())
self.progressBar.setValue( self.progressBar.value() + 1 )
intersects = index.intersects(geom.boundingBox())
for id in intersects:
inputProvider.featureAtId(int(id), infeat, True)
tmpGeom = QgsGeometry( infeat.geometry() )
if geom.intersects(tmpGeom):
selectedSet.append(infeat.id())
self.progressBar.setValue(self.progressBar.value()+1)
if modify == self.tr("adding to current selection"):
selectedSet = list(set(inputLayer.selectedFeaturesIds()).union(selectedSet))
elif modify == self.tr("removing from current selection"):

0 comments on commit 6e48297

Please sign in to comment.