I have a shapefile with points, and a shapefile with polygons. I want to sum the attribute value of all points that are within a certain polygon, and I'd like to do this for each polygon in my dataset. QGIS Join Attributes by Location tool is helping me to achieve this, and is working perfectly when using the tool via the Processing Toolbox. However, I would like to include the tool in an automated script. I tried many different arguments, but my code is (still) not working, and results in a dataset where the new polygon attribute has NULL values.

I'm using the following code, which should be exactly the same as the tool is running when I'm accessing it from the Processing Toolbox (I even tried copying and running the exact same code from the History & Log window):

sum = processing.runalg("qgis:joinattributesbylocation","polygonlayer.shp",

I'm using QGIS 2.8.2 Wien.

  • Welcome to GIS:SE Linda! Are you sure the algorithm is not qgis:joinbylocation which is what I have?
    – Joseph
    Commented Jun 9, 2015 at 13:09
  • Thanks! Using qgis:joinbylocation does not work for me ("Error: Algorithm not found"). Are you using QGIS 2.8.2?
    – Linda
    Commented Jun 9, 2015 at 13:18
  • Ignore my previous comment, I didn't update the processing plugin. I always forget this!
    – Joseph
    Commented Jun 9, 2015 at 13:21
  • Similar problem here too as it also doesn't work through the modeler.
    – Joseph
    Commented Jun 9, 2015 at 14:12
  • Most welcome, as mentioned in a comment by @mike from the post I linked, downgrading the processing plugin to 2.2 and using the qgis:joinbylocation tool works. I just downgraded it again as I personally consider it very stable even though it has less tools available than the latest versions. You can download the plugin from here and unzip the folder to your C:\Users\You\.qgis2\python\plugins directory. Hope this helps a little anyway!
    – Joseph
    Commented Jun 9, 2015 at 14:33

1 Answer 1

  • For QGIS 2.8.2 with Processing plugin 2.9.0:

    processing.runalg("qgis:joinattributesbylocation", layer1, layer2, u'contains', 1, 'sum', 1, None)
  • For QGIS 2.12.2 with Processing plugin 2.12.2:

    processing.runalg("qgis:joinattributesbylocation", layer1, layer2, u'contains', 0, 1, 'sum', 1, None)

    (note the extra parameter for "precision")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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