I try to use the processing 'qgis:extractbylocation' in QGIS 2.8.2 from the QGIS algorithm provider.

import processing
# import the layers by a given uri
inputlayer = QgsVectorLayer(uriTr.uri(), "inputlayer", "postgres")
intersectlayer = QgsVectorLayer(uriOSM.uri(), "intersectlayer", "postgres")

# initialize a predicate instance
pred_intersects = processing.core.parameters.ParameterGeometryPredicate(enabledPredicates = 'intersects')
# run the processing
processing.runalg('qgis:extractbylocation', inputlayer, intersectlayer, pred_intersects, None)

However I get the following error:

Traceback (most recent call last):
    File "<input>", line 1, in <module>
    File "~/.qgis2/python/plugins/processing/tools/general.py", line 71, in runalg
        alg = Processing.runAlgorithm(algOrName, None, *args)
    File "~/.qgis2/python/plugins/processing/core/Processing.py", line 317, in runAlgorithm
        if not param.setValue(args[i]):
    File "~/.qgis2/python/plugins/processing/core/parameters.py", line 829, in setValue
        elif len(value) == 0:
AttributeError: ParameterGeometryPredicate instance has no attribute '__len__'

The algorithm needs the following inputs

     ALGORITHM: Extract by location
     INPUT <ParameterVector>
     INTERSECT <ParameterVector>
     PREDICATE <ParameterGeometryPredicate>
     OUTPUT <OutputVector>

ParameterGeometryPredicate is described here: https://fossies.org/dox/qgis-2.8.2/classprocessing_1_1core_1_1parameters_1_1ParameterGeometryPredicate.html

How do I need to initialize a correct instance of the ParameterGeometryPredicate class?


The predicate is u'intersects'. For more than one predicate use an array like "[u'within',u'intersects']"

The full command is

processing.runalg('qgis:extractbylocation', inputlayer, intersectlayer, u'intersects', None)

The possible arguments for the predicates are:


The similar algorithm selectbylocation is used like

processing.runalg('qgis:selectbylocation', inputlayer, intersectlayer, u'intersects', 0)
  • Why do I need to mark it as an Unicode string? And why isn't this necessary for the GUI?
    – telemachos
    Jun 15 '15 at 13:24
  • 2
    Because the encoding of the GUI is unicode
    – gene
    Jun 15 '15 at 16:18

Run the "Extract by location" command of the Toolbox and examine the last line of the ../.qgis2/processing/processing.log file (that records all the commands executed)

ALGORITHM|Sun Jun 14 2015 17:34:39|

The predicate is simply "['intersects']"

  • This does not work. In the script /.qgis2/python/plugins/processing/algs/qgis/SelectByLocation.py there is the loop for predicate in predicates: This loop just iterates over the single chars of "['intersects']". You won't get an error, but no selected features either.
    – telemachos
    Jun 15 '15 at 13:04

this works for me:


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.