2

I have a problem. I am developing a standalone app in python and I need to use processing algorithms. I was able to use one algorithm without erros but I need to run other processing algorithm which input is the output of the first one. So, my program stops in the first algorithm. Why it doesn't read the second one?

CODE:

import sys

from qgis.core import QgsApplication, QgsVectorLayer
from PyQt4.QtGui import QApplication
from PyQt4.QtCore import QFileInfo
import GdalTools_utils
import ftools_utils
import osgeo
import ogr
import gdal
app = QApplication([])
QgsApplication.setPrefixPath("/usr", True)
QgsApplication.initQgis()

from processing.core.Processing import Processing
Processing.initialize()

inputLayer = QgsVectorLayer(...)
inputMask = QgsVectorLayer(...)

extent_rect = inputMask.extent()

xmin = extent_rect.xMinimum()
xmax = extent_rect.xMaximum()
ymin = extent_rect.yMinimum()
ymax = extent_rect.yMaximum()
extent = str(xmin) + "," + str(xmax) + "," + str(ymin) + "," + str(ymax)

cellsize = 30
outrains10 = '...'

count = inputLayer.featureCount()

rain_10 = 'rains10'
days_10 = 'days10'

Processing.runAlgorithm("grass:v.surf.idw", None, inputLayer, count, 2.0,rain_10, False,extent, cellsize, -1.0, 0.0001, outrains10)

Processing.runAlgorithm("saga:clipgridwithpolygon", None, outrains10 , inputMask, outclip_rains10)

So the first algorithm grass is OK. The output is fine. But I want to use it as input in the second one, but the code stops there.

UPDATE

The code stops because I didn't know that I have to install SAGA to use in linux. Now I have SAGA installed (I run from QGIS and everything is ok) but I still don't know how to configure saga to read through processing, such as the line:

Processing.runAlgorithm("saga:clipgridwithpolygon", None, outrains10 , inputMask, outclip_rains10)

UPDATE

I still doesn't get saga working but with many many tries, I found that, when I run the script, an error (Segmentation fault) and others are returned. So debugging my code I found that is the input raster which gives the error:

example:

grid = QgsRasterLayer('/.../raster.tif')

Does anyone knows why this is happen?? Can you help me please?

  • In this post you find an example of using an algorithm's output as input for another algorithm. – Germán Carrillo Jan 29 '15 at 15:24
  • 1
    Hi Barbara, you should also post your script each time you ask a question, even if it's the exact same script as in your previous questions :). – Joseph Jan 29 '15 at 15:25
  • I see these post (gis.stackexchange.com/questions/129915/…) but I don't need a for loop. And also I try anything to print after the first processing and nothing occurs. – Bárbara Duarte Jan 29 '15 at 15:33
  • Could it be that your output for the first algorithm is a raster and you haven't imported QgsRasterLayer from qgis.core? – Joseph Jan 29 '15 at 15:42
  • I try with that too. Before the second algorithm I use QgsRasterLayer(directory, name, 'tif') but without success. To test I try also: Processing.getAlgorithm('saga:clipgridwithpolygon') but it doesn't read that. I don't know why. – Bárbara Duarte Jan 29 '15 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.