[Qgis-developer] Processing scripts in stand-alone Python scripts

Seno Adiwicaksono senoadiw at gmail.com
Fri Nov 27 01:46:30 PST 2015


Hi,

I think you can try calling ProcessingConfig.setSettingValue() to set the
script dir before initializing. Here is how I did it with R scripts in
R_SCRIPTS_FOLDER:

from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.Processing import Processing
ProcessingConfig.setSettingValue('ACTIVATE_R', True)
ProcessingConfig.setSettingValue('R_FOLDER', os.environ['RPATH'])
ProcessingConfig.setSettingValue('R_LIBS_USER', os.environ['RLIBS'])
ProcessingConfig.setSettingValue('R_SCRIPTS_FOLDER', os.environ['RSCRIPTS'])
Processing.initialize()
from processing.tools import *

outputs = general.runalg('r:myscript')

Cheers,

SN


On Thu, Nov 26, 2015 at 5:06 PM, Anita Graser <anitagraser at gmx.at> wrote:

> Hi,
>
> I'm trying to run Processing scripts in a stand-alone Python script. The
> examples available online for calling default, e.g. QGIS algorithms, work
> fine but when I try to access a script instead, it cannot be found, i.e.
> getAlgorithm() returns None.
>
> Am I missing something or is this a bug?
>
> # Prepare the environment
> import sys
> from qgis.core import QgsApplication
> from PyQt4.QtGui import QApplication
> app = QApplication([])
> QgsApplication.setPrefixPath("/usr", True)
> QgsApplication.initQgis()
>
> # Prepare processing framework
> sys.path.append('/home/agraser/.qgis2/python/plugins')
> from processing.core.Processing import Processing
> Processing.initialize()
>
> print Processing.getAlgorithm("qgis:creategrid") # works
> print Processing.getAlgorithm("script:helloworld") # doesn't work
>
> # Exit applications
> QgsApplication.exitQgis()
> QApplication.exit()
>
>
> Thanks and best wishes,
> Anita
>
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20151127/4189ef0e/attachment.html>


More information about the Qgis-developer mailing list