Sunday, 2 September 2018

pyqgis - Running processing toolbox outside QGIS in standalone app?


I am developing a standalone app in Python, using QGIS libraries including processing algorithms. I am developing in Linux environment and I put the libraries in a folder. Also I put the processing folder from QGIS in that same folder. I run the app but when I import the processing folder, it gives me nothing (not even error messages).


I import like that:



import processing.core.Processing

Can you help me?


CODE:


import sys
import qgis.core
import PyQt4.QtCore
import PyQt4.QtGui
app = qgis.core.QgsApplication([],True)
qgis.core.QgsApplication.setPrefixPath("/usr", True)

qgis.core.QgsApplication.initQgis()

(from here the program doesn't work)


from processing.core.Processing import Processing
inputLayer = 'c:....'
inputMask = 'c:....'

extent = ....
cellsize = ....
outPath = 'c:.....'


Processing.Initialize()
Processing.runalgorith(.....)



I downloaded the folder with the processing version 2.2.0-2 and I copied to my script folder. I run and it gives me this error:


Traceback (most recent call last):
File "teste.py", line 12, in
from processing.core.Processing import Processing
File "/home/p/Programas/processing/__init__.py", line 28, in

from processing.tools.dataobjects import *
File "/home/p/Programas/processing/tools/dataobjects.py", line 33, in
from processing.core.ProcessingConfig import ProcessingConfig
File "/home/p/Programas/processing/core/ProcessingConfig.py", line 30, in
from processing.tools.system import *
File "/home/p/Programas/processing/core/processing.py", line 33, in
from processing import interface
ImportError: cannot import name interface




I got it!! What is missing in my case was to define the PYTHONPATH to the folder with the processing. Now I have the correct running of the code.




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...