[Qgis-developer] Using Processing in standalone PYQGIS scripts

Eric Goddard egoddard1010 at gmail.com
Thu Sep 29 13:39:33 PDT 2016


Hello everyone,

I'm using QGIS 2.16.3 on Ubuntu 14.04 (from the qgis.org/ubuntugis
repo with ubuntugis-unstable ppa). I have a geopackage layer (I
originally started out with a spatialitelayer, but I kept getting

ASSERT: "i.value() == handle" in file
/tmp/buildd/qgis-2.16.3+20trusty/src/providers/spatialite/qgsspatialiteconnection.cpp,
line 780
Aborted (core dumped)

when calling getFeatures() on the layer) with two columns that I want
to populate. One contains the month and year a photo was taken,
extracted from EXIF metadata. The other is for the name of the polygon
that contains the point feature. Extracting the date from the metadata
works fine, but I'm having some serious difficulties with running the
'qgis:selectbylocation' processing algorithm in a standalone script.
Stack Overflow has several posts on using Processing in standalone
scripts, the most recent of which [1] I tried. It crashes on line 15
in my script [2](Processing.initialize()) with the following error
message:

The current error message I'm getting is:
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/qgis/utils.py", line 196, in
qgis_excepthook
    showException(type, value, tb, None, messagebar=True)
  File "/usr/lib/python2.7/dist-packages/qgis/utils.py", line 107, in
showException
    open_stack_dialog(type, value, tb, msg)
  File "/usr/lib/python2.7/dist-packages/qgis/utils.py", line 142, in
open_stack_dialog
    iface.messageBar().popWidget()
AttributeError: 'NoneType' object has no attribute 'messageBar'

Original exception was:
Traceback (most recent call last):
  File "extract_image_dates.py", line 14, in <module>
    Processing.Initialize()
AttributeError: class Processing has no attribute 'Initialize'


Since I was unable to get it running in the standalone script, I
loaded the script I wrote in the QGIS Python console. It ran, but it
said that the number of arguments to 'qgis:selectbylocation' was
wrong, but my call to the algorithim on line 55 matches the docs [3].

Any pointers on how to get this working would be greatly appreciated,
and I'd be happy to make a PR on the QGIS Documentation to add a
section about it once it works.


Thanks!
Eric

[1] http://gis.stackexchange.com/questions/129915/cannot-run-standalone-qgis-script
[2] https://gist.github.com/egoddard/c188c62115f2fe8df24f32b3119e51b3
[3] http://docs.qgis.org/2.14/en/docs/user_manual/processing_algs/qgis/vector_selection_tools.html#select-by-location


More information about the Qgis-developer mailing list