2

I am having trouble with my code for selecting all points within a buffer layer, with the error given below. I am using this documentation as reference for the field formats: https://docs.qgis.org/2.6/en/docs/user_manual/processing_algs/qgis/vector_selection_tools/selectbylocation.html . I also tried the solution posted here How to use qgis:selectbylocation in PyQGIS? . Is there something that I'm missing?

processing.runalg("qgis:selectbylocation", 
                  "/Users/pgcseismolab/Desktop/qgis/moment_all.shp",
                  "/Users/pgcseismolab/Desktop/jaden_pgc_archive/Blast_Files/Blast_buffers/blast_induced_buff.shp", 
                  False, 
                  False, 
                  False, 
                  0)

Error: Wrong number of parameters
ALGORITHM: Select by location
    INPUT <ParameterVector>
    INTERSECT <ParameterVector>
    PREDICATE <ParameterGeometryPredicate>
    PRECISION <ParameterNumber>
    METHOD <ParameterSelection>
    OUTPUT <OutputVector>

METHOD(Modify current selection by) 0 - creating new selection 1 - adding to current selection 2 - removing from current selection

EDIT: I am using QGIS 2.14, and have updated my code as follows (with the error below). Following documentation posted here: http://docs.qgis.org/2.14/en/docs/user_manual/processing_algs/qgis/vector_selection_tools.html?highlight=selectbylocation

processing.runalg("qgis:selectbylocation", 
                  "/Users/pgcseismolab/Desktop/qgis/moment_all.shp", 
                  "/Users/pgcseismolab/Desktop/jaden_pgc_archive/Blast_Files/Blast_buffers/blast_induced_buff.shp", 
                  'within', 
                  0)

Error: Wrong number of parameters
ALGORITHM: Select by location
    INPUT <ParameterVector>
    INTERSECT <ParameterVector>
    PREDICATE <ParameterGeometryPredicate>
    PRECISION <ParameterNumber>
    METHOD <ParameterSelection>
    OUTPUT <OutputVector>
PolyGeo
  • 65,136
  • 29
  • 109
  • 338
jrowley
  • 257
  • 1
  • 8

1 Answers1

2

You can always use the Processing algorithm from QGIS GUI and then go to Processing -> History to see how to run the algorithm in QGIS Python Console.

processing.runalg("qgis:selectbylocation", 
    "/Users/pgcseismolab/Desktop/qgis/moment_all.shp", 
    "/Users/pgcseismolab/Desktop/jaden_pgc_archive/Blast_Files/Blast_buffers/blast_induced_buff.shp", 
    ['within'], 
    0, 
    0)

Note that:

  • PREDICATE parameter should be passed as a Python array of strings: ['within'] instead of 'within'.
  • You're missing the second to last parameter called PRECISION, which in the command above is 0. Of course, you can adjust it according to your scenario.
Germán Carrillo
  • 36,307
  • 5
  • 123
  • 178
  • These 2 additions resolved my issue- thank you! The code in your answer worked perfectly. I didn't know about the processing -> history option; I'll certainly be using this more often :) – jrowley Jul 17 '17 at 20:56
  • You're welcome. Right, that's a very handy log. – Germán Carrillo Jul 17 '17 at 20:58