Thursday, 15 October 2015

qgis modeler - Why can't I use processing algorithms in a standalone PyQGIS script?


I want to create a standalone python script using QGIS python API (PYQGIS) for education. First I create a model and export that model to python script.


original python script from the export :


##=name
##raster=raster
##stat=output html
outputs_QGISRASTERLAYERSTATISTICS_1=processing.runalg('qgis:rasterlayerstatistics', raster,stat)


Next I read this Using PyQGIS in standalone scripts and I tried to follow this tutorial to create my script.


Final script :


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/username/.qgis2/python')
from processing.core.Processing import Processing
dem='aster.tif'
slope='slope.tif'
aspect='aspect.tif'
outputs_SAGASLOPEASPECTCURVATURE_1=processing.runalg('saga:slopeaspectcurvature', dem,6,1,1,slope,aspect,None,None,None,None,None,None,None,None,None,None)
Processing.initialize()

# Exit applications
QgsApplication.exitQgis()

QApplication.exit()

If I run this script it works fine without error but I don't take some export like aspect and slope (these can't be found?). Any idea why I can't take exports ?


I use Ubuntu and python 2.7 and QGIS 2.18.1.




i try to this script :


import sys
from qgis.core import QgsApplication
sys.path.append('/usr/share/qgis/python/plugins')
import processing

a=processing.alglist()
print a
processing.alghelp("saga:slopeaspectcurvature")

and i take that print any idea why ?


Algorithm not found

but if i use this module in QGIS work fine.




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