Implementing feature selection
Now, when dialogs are created and connected to our plugin, we can start implementing the main functionality—namely, feature selection using requirements defined by the user.
Open the selectradiusdialog.py
file located in the gui
subdirectory of the plugin source tree. Add the following code at the end of the accept()
method:
( 1) self.btnOk.setEnabled(False) ( 2) self.btnClose.setEnabled(False) ( 3) ( 4) request = QgsFeatureRequest() ( 5) request.setFlags( ( 6) request.flags() ^ QgsFeatureRequest.SubsetOfAttributes) ( 7) ( 8) index = QgsSpatialIndex(targetLayer.getFeatures(request)) ( 9) (10) selection = [] (11) for f in referenceFeatures: (12) geom = QgsGeometry(f.geometry()) (13) bufferedGeometry = geom.buffer(self.spnRadius.value(), 5) (14) (15) intersectedIds = index.intersects(bufferedGeometry.boundingBox()) (16) (17) self.progressBar.setRange(0, len(intersectedIds...