Bug report #14645

"select by expression” algorithm in modeler

Added by Aitor Forcada over 4 years ago. Updated over 4 years ago.

Status:Rejected
Priority:Normal
Assignee:Victor Olaya
Category:Processing/Modeller
Affected QGIS version:2.14.0 Regression?:No
Operating System:win 7 (64) Easy fix?:No
Pull Request or Patch supplied:No Resolution:wontfix
Crashes QGIS or corrupts data:No Copied to github as #:22609

Description

I was getting wrong results when I applied “select by expression” algorithm in the graphical modeler (QGIS 2.14.1), even thought when I saved the selected features in an intermediate temporal shapefile before perform the geoprocessing. I’m trying to count points that intersect with polygons in a vector grid, but filtering the points shapefile depending on several queries based on the attribute table. I want to do a first query and count the points, and do a second query and repeat the counting, saving both counts in the same layer. Using this model, I get in both counts the same results, just the one that correspond with the last selection.
I solve this problem, using “Extract by attribute” instead of “select by expression” algorithm. It seems that “select by expression” algorithm doesn’t work well when computing several selections in the same model.

a.jpg (82.3 KB) Aitor Forcada, 2016-04-08 11:33 AM

global_fisheries_prue_selection_no_funciona.model (10.9 KB) Aitor Forcada, 2016-04-10 10:02 AM

Shapefiles.7z (599 KB) Aitor Forcada, 2016-04-10 10:02 AM

History

#1 Updated by Giovanni Manghi over 4 years ago

  • Target version deleted (Version 2.14)

#2 Updated by Alexander Bruy over 4 years ago

  • Status changed from Open to Feedback

Please attach model itself ans sample dataset.

#4 Updated by Alexander Bruy over 4 years ago

  • Status changed from Feedback to Closed
  • Resolution set to wontfix

Well, this is not a bug. By default Processing works only with selected features if there is a selection in a layer. So when your model executed, it created selection in the point layer and all other algorithms then work with this selection.

You have two solutions here:
  1. use "Extract By Attribute" algorithm. This also will simplify your model
  2. uncheck "Use only selected features" option in Processing → Options. In this case all algorithms will process whole layer regardless of the selection.

Feel free to reopen if you think that there is an issue.

#5 Updated by Aitor Forcada over 4 years ago

  • Status changed from Closed to Reopened

This is exactly the point, the model doesn’t work with the correct selected features during the processing. In the model I tried to do two processing steps using two different selections, but both results corresponded just with the last selection (I mean, two different selections but the same result in both processing). This happened, even though I applied sequentially the instructions in the model: Selection->Processing->New selection->Processing. In fact, I incorporated an intermediate step to “save selected features” in a temporal shapefile with the aim to fix the selected features, but still not working. As I mentioned in the main bug report, I solved this problem using “Extract by attribute”, your suggestion works. However, I considered that I should report the problem as a bug. Additionally, if I’m not wrong, with “select by expression” algorithm, several fields can be used in the query, but with “Extract by attribute” you need to incorporate several steps if many different fields are used in the query. Thank you for your time and work.

#6 Updated by Alexander Bruy over 4 years ago

  • Status changed from Reopened to Rejected

Aitor Forcada wrote:

This is exactly the point, the model doesn’t work with the correct selected features during the processing.

It also won't work if you try to run algs manually one by one. Because Processing by default used only selected features. You can change this behaviour as I said in previous comment and then it will work.

This happened, even though I applied sequentially the instructions in the model: Selection->Processing->New selection->Processing.

Again, Processing operates with selected features, not with whole layer. When first "Select by expression" alg executed it creates selection in layer. And all subsequent algorithms will work with this selection. This is not a bug. More over, as I already said, this behaviour can be configured. There is nothing wrong here and nothing to fix.

#7 Updated by Aitor Forcada over 4 years ago

Maybe I didn’t explain the problem very well. I know that processing tools use to work with selected features, inside and outside the modeler. Just to understand better your answer and what is behind the modeler, I tried your second suggestion of uncheck "Use only selected features" option in Processing → Options, and also I get wrong results. Running the model in this way, I get the count of all the points of the layer, and not of those that reach the query applied in the selection. Anyway, as I mentioned before, I solved my problem using “Extract by attribute” before reporting the supposed bug. So, if you consider that it is not a bug sorry for the inconvenience.

Also available in: Atom PDF