Geographic Information Systems Asked by Tim Jones on January 10, 2021
I’m using QGIS 2.14.3 – Essen (but have also tried 2.18.12 Las Palmas)
Using 2.14.3, if I select one feature in a vector layer, and then use [Vector][Research][Select by Location], I have the option to check the ‘Only selected features’ option (this feature is not available in 2.18.12). The analysis behaves as one would expect if only the selected feature is used.
In newer releases, the dialogue box doesn’t have an option to only analyse selected features and the outcome is different to case 1 above (in that all features in the layer are processed, irrespective of how many may be selected)
I can see that in [Processing][Options][General], there is an option to ‘only use selected features’ but it appears to me that this is not used – irrespective of whether this box is checked or unchecked, the select by location algorithm uses all features, not selected features.
Not sure if still actual but recently I have found a solution with no settings correction. I needed to iterate some selected features and get all intersections from other layers. Then make a pack of folders with same layers containing different features.
When you want to specify only selected
option the processing script is written in a bit another way.
Firstly you have to get an id string of your layer. Then put that string into a processing script but wrapped in QgsProcessingFeatureSourceDefinition
with True
parameter and then you are ready to perform a selection using only selected input features.
import processing
# getting a layer with selected features with 'FrameLayer' project name
lName = "FrameLayer"
lNameVL = list(filter(lambda x: x.name() == lName , list(QgsProject.instance().mapLayers().values())))[0]
# getting its id string
lNameId = lNameVL.id()
# selecting features from active layer intersecting lNameVL layer using 'only selected' option
processing.run("qgis:selectbylocation", {'INPUT': iface.activeLayer(), 'PREDICATE': 0, 'INTERSECT':QgsProcessingFeatureSourceDefinition(lNameId, True), 'METHOD':0})
Answered by Pavel Pereverzev on January 10, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP