Monday, 6 March 2017

pyqgis - QGIS Join Attributes by Location not working from Python script


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",
"pointlayer.shp","['contains']",1,"sum",1,None)

I'm using QGIS 2.8.2 Wien.




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...