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 errors 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 can'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?

nmtoken
  • 13,355
  • 5
  • 38
  • 87
Bárbara Duarte
  • 1,451
  • 4
  • 18
  • 31
  • 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 (http://gis.stackexchange.com/questions/129915/cannot-run-standalone-qgis-script/130304#130304) 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
  • Try using import * instead of naming your modules separately (eg. from qgis.core import *, I find this a useful method as it imports most modules (if not all) related to the class. – Joseph Jan 29 '15 at 16:00
  • I try that. It is importing very well the raster tif. But not reads the second processing, even when I use: Processing.getAlgorithm('...') just to test. – Bárbara Duarte Jan 29 '15 at 17:28
  • Try defining the output outclip_rains10 in your second algorithm. – Joseph Jan 30 '15 at 10:38
  • So, the script recognize the raster file and I put that definition right before the second algorithm but still doesn't work. – Bárbara Duarte Jan 30 '15 at 14:58
  • Nevermind. I find the answer. SAGA is not correctly instaled in my system. – Bárbara Duarte Jan 30 '15 at 15:21
  • Now, I install saga through: sudo apt-get install saga and it creates a folder in usr/share/saga. It is normal? Because Ii search and I see that saga usually are in usr/lib/. – Bárbara Duarte Jan 30 '15 at 17:30

0 Answers0