Skip to content

Commit

Permalink
Update to select by location tool: should run faster for large layers…
Browse files Browse the repository at this point in the history
…, and requires less memory. Should also fix #1669

git-svn-id: http://svn.osgeo.org/qgis/trunk@13205 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
cfarmer committed Mar 30, 2010
1 parent febbca5 commit 67376a6
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions python/plugins/fTools/tools/doSelectByLocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down

0 comments on commit 67376a6

Please sign in to comment.