3

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.

7
  • From the menubar, go to Processing > Options > General and make sure the Use only selected features option is checked. Now when you run your processing algorithms, it should only run on those features which were selected. On a side-note, you should consider downloading a more recent version of QGIS (currently 2.18). – Joseph Aug 14 '17 at 12:50
  • Thanks for taking the time to respond, Joseph. I don't believe that 2.14.3 uses that option correctly - my results don't change either way (checked or unchecked). I take your point re using a more recent version but it's a corporate installation and not within my control. – Tim Jones Aug 14 '17 at 14:21
  • Strange, works fine for me. A possible workaround could be to just select your points from your original layer, right-click and use the Save As... option to save the selected features as a new shapefile and then run the Select by location tool on this new shapefile :) – Joseph Aug 15 '17 at 11:30
  • I tried [Save As] but I experience exactly the same outcome. My layer has 17 features. If I select one feature which I know 'touches' 3 other featues, and I use [Vector][Research Tools][Select by Location] and check the "Only selected features" option, then QGIS returns the correct 3 features. If I use [Processing][Toolbox][Select by Location] (having previously checked [Processing][Options][General] "Use only selected features" then QGIS returns all 17 features. Checking and unchecking the option makes no difference - QGIS always returns all 17 features (ignoring the option) – Tim Jones Aug 15 '17 at 14:45
  • Sounds like a bug. The LTR version for QGIS is 2.14.17, you could ask to download this version. I would assume most bugs would be fixed. – Joseph Aug 15 '17 at 14:49
2

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})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.