Bug report #17162

Processing: select by location does not work in the modeller

Added by Giovanni Manghi about 7 years ago. Updated about 7 years ago.

Status:Closed
Priority:Normal
Assignee:Victor Olaya
Category:Processing/Modeller
Affected QGIS version:2.18.12 Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:invalid
Crashes QGIS or corrupts data:No Copied to github as #:25061

Description

Within a model the "select by location" (followed by a "save selected features") tool does not work, the result is always an error

Error executing algorithm Save selected features There are no selected features in the input layer.

Tested on Linux and Windows on 2.18.13


Related issues

Related to QGIS Application - Feature request #17211: remove/hide the "select by location" tool from modeller Closed 2017-09-28

History

#1 Updated by Harrissou Santanna about 7 years ago

Giovanni, does it work when using directly from the toolbox for you?
I tried using it (with eg contains or intersect predicates) and fail to return any feature. Same layers used with the Clip algorithm return expected (clipped) features.
I'm on master 8902d5f48f

#2 Updated by Harrissou Santanna about 7 years ago

Ah sorry, Just realized that this is a 2.18 bug report. Do you think I should open a master-related ticket ?

#3 Updated by Giovanni Manghi about 7 years ago

Harrissou Santanna wrote:

Giovanni, does it work when using directly from the toolbox for you?
I tried using it (with eg contains or intersect predicates) and fail to return any feature. Same layers used with the Clip algorithm return expected (clipped) features.
I'm on master 8902d5f48f

Can you check if your inputs have multipart geometries? Now that you say that I remember having issues with inputs with multipart geometries, if confirmed (that works only with singlepart inputs) then a new ticket should be filed.

I'm not duplicating tickets for 2.18 and master, not until now at least.

#4 Updated by Nyall Dawson about 7 years ago

Harrissou - can you share your data? I'll look into this.

#5 Updated by Alexander Bruy about 7 years ago

Use "Extract by Location" instead, it was added to overcome this issue.

#6 Updated by Giovanni Manghi about 7 years ago

Alexander Bruy wrote:

Use "Extract by Location" instead, it was added to overcome this issue.

Can we hide (in the modeler) the one that does not work in the modeler?

#7 Updated by Harrissou Santanna about 7 years ago

Giovanni Manghi wrote:

Alexander Bruy wrote:

Use "Extract by Location" instead, it was added to overcome this issue.

Can we hide (in the modeler) the one that does not work in the modeler?

In which case a message advising to use the extract tool instead of select tool in modeler should be added (in the select tool help).

Can you check if your inputs have multipart geometries?

They are indeed. st_geometrytype(geom) returns ST_MULTIPOLYGON for both layers though no multiple parts features is concerned in the extent I'm trying to select from.
When I launch the selection command, the dialog is closed almost instantly and I have no message

Nyall, in order to send you data, I save as shapefile the layer from which i wanted to select features. Then I run a select by location test against that new layer. And weirdly things went nicely.
Checking the geometrytype of the features from the virtual layers dialog, select st_geometrytype(geometry), st_numgeometries(geometry) from myshapefilelayer returns the same result as with my original PostgreSQL layers.

These are the commands from Processing History

processing.run("native:selectbylocation", {'INPUT':'//serveur/Serveur CAUE/SIG/DATA_2/TEMP/qgis_issues/sele_loc_issues.shp','PREDICATE':[0],'INTERSECT':QgsProcessingFeatureSourceDefinition('perimetre_operationnel20160505180346904', True),'METHOD':0})

processing.run("native:selectbylocation", {'INPUT':'dbname='ref' host=localhost port=5432 user='delazj' sslmode=disable key='ogc_fid' table='cadastre'.'geo_parcelle' (geom) sql=','PREDICATE':[0],'INTERSECT':QgsProcessingFeatureSourceDefinition('perimetre_operationnel20160505180346904', True),'METHOD':0})

Running them in the python console succeeds for the shapefile and for the postgis layer returns
Traceback (most recent call last):
  File "C:\OSGEO4~1\apps\Python36\lib\code.py", line 64, in runsource
    code = self.compile(source, filename, symbol)
  File "C:\OSGEO4~1\apps\Python36\lib\codeop.py", line 168, in __call__
    return _maybe_compile(self.compiler, source, filename, symbol)
  File "C:\OSGEO4~1\apps\Python36\lib\codeop.py", line 99, in _maybe_compile
    raise err1
  File "C:\OSGEO4~1\apps\Python36\lib\codeop.py", line 87, in _maybe_compile
    code1 = compiler(source + "\n", filename, symbol)
  File "C:\OSGEO4~1\apps\Python36\lib\codeop.py", line 133, in __call__
    codeob = compile(source, filename, symbol, self.flags, 1)
  File "<input>", line 1
    processing.run("native:selectbylocation", {'INPUT':'dbname='ref' host=localhost port=5432 user='delazj' sslmode=disable key='ogc_fid' table='cadastre'.'geo_parcelle' (geom) sql=','PREDICATE':[0],'INTERSECT':QgsProcessingFeatureSourceDefinition('perimetre_operationnel20160505180346904', True),'METHOD':0})
                                                                          ^
SyntaxError: invalid syntax

Hope that helps

#8 Updated by Giovanni Manghi about 7 years ago

Hi Harrissou

Can you check if your inputs have multipart geometries?

They are indeed.

I'm personally unable to replicate the issues with multipart geoms in 2.18.13... I might recall incorrectly or just using the wrong dataset.
If you confirm issues on master this would need a separate ticket as anyway this must be closed to make a feature request (remove/hide the "select by location" tool from modeller).

cheers!

#9 Updated by Nyall Dawson about 7 years ago

Harrissou what about dumping the sql from the tables?

processing.run("native:selectbylocation", {'INPUT':'dbname='ref' host=localhost port=5432 user='delazj' sslmode=disable key='ogc_fid' table='cadastre'.'geo_parcelle' (geom) sql=','PREDICATE':[0],'INTERSECT':QgsProcessingFeatureSourceDefinition('perimetre_operationnel20160505180346904', True),'METHOD':0})
^
SyntaxError: invalid syntax

Can you file a separate bug for this one? ("processing history doesn't handle postgres source tables correctly")

#10 Updated by Giovanni Manghi about 7 years ago

  • Status changed from Open to Closed
  • Resolution set to invalid

Replaced by #17211

#11 Updated by Jürgen Fischer about 7 years ago

Also available in: Atom PDF