5

I want to sum the cell values from 3 grids. I have a list of file paths (temp layers) generated in a "for" loop, looking like the following one. I cannot understand why the function makes some transformations and takes 7 input grids, when it should load and sum 3 grids.

If I sum these files in SAGA GUI, the result is the expected one. But when I sum the files using PyQGIS, the last raster is summed 7 times (see the end of the log).

Can anyone help me?

Here is my code:

s1 = "E:/rcal/OUTPUT11.sdat"
s2 = "E:/rcal/OUTPUT22.sdat"
s3 = "E:/rcal/OUTPUT33.sdat"

list = [s1,s2,s3]
result = processing.runalg('saga:gridssum',list, None)

And this is the processing log:

        #####   ##   #####    ##
        ###     ###  ##       ###
        ###   # ## ##  #### # ##
        ### ##### ##    # #####
        ##### #   ##  ##### #   ##
        _____________________________________________

        _____________________________________________
        library path:   C:\PROGRA~1\QGIS2~1.18\apps\saga\modules\grid_calculus.dll
        library name:   Grid - Calculus
        tool name   :   Grids Sum
        author      :   O. Conrad (c) 2010
        _____________________________________________

        Parameters

        Grids: No objects
        Files: E:/rcal/OUTPUT11.sdat
        Transformation: yes
        Interpolation: B-Spline Interpolation           

        loading: E:/rcal/OUTPUT11.sdat


        Driver: SAGA

        Bands: 1

        Rows: 177

        Columns: 139



        Transformation:

        x' = 381422.717257 + x * 5.000000 + y * 0.000000

        y' = 433062.210367 + x * 0.000000 + y * -5.000000


        loading band [1/1]



        Parameters


        Grids: 1 object (OUTPUT11)
        Files: E:/rcal/OUTPUT22.sdat
        Transformation: yes
        Interpolation: B-Spline Interpolation


        loading: E:/rcal/OUTPUT22.sdat



        Driver: SAGA

        Bands: 1

        Rows: 177

        Columns: 139



        Transformation:

        x' = 381422.717257 + x * 5.000000 + y * 0.000000

        y' = 433062.210367 + x * 0.000000 + y * -5.000000


        loading band [1/1]






        Parameters


        Grids: 1 object (OUTPUT22)
        Files: E:/rcal/OUTPUT11.sdat
        Transformation: yes
        Interpolation: B-Spline Interpolation


        loading: E:/rcal/OUTPUT11.sdat



        Driver: SAGA

        Bands: 1

        Rows: 177

        Columns: 139



        Transformation:

        x' = 381422.717257 + x * 5.000000 + y * 0.000000

        y' = 433062.210367 + x * 0.000000 + y * -5.000000


        loading band [1/1]



        Parameters


        Grids: 1 object (OUTPUT11)
        Files: E:/rcal/OUTPUT22.sdat
        Transformation: yes
        Interpolation: B-Spline Interpolation


        loading: E:/rcal/OUTPUT22.sdat



        Driver: SAGA

        Bands: 1

        Rows: 177

        Columns: 139



        Transformation:

        x' = 381422.717257 + x * 5.000000 + y * 0.000000

        y' = 433062.210367 + x * 0.000000 + y * -5.000000


        loading band [1/1]



        Parameters


        Grids: 1 object (OUTPUT22)
        Files: E:/rcal/OUTPUT22.sdat
        Transformation: yes
        Interpolation: B-Spline Interpolation


        loading: E:/rcal/OUTPUT22.sdat



        Driver: SAGA

        Bands: 1

        Rows: 177

        Columns: 139



        Transformation:

        x' = 381422.717257 + x * 5.000000 + y * 0.000000

        y' = 433062.210367 + x * 0.000000 + y * -5.000000


        loading band [1/1]



        Parameters


        Grids: 1 object (OUTPUT22)
        Files: E:/rcal/OUTPUT11.sdat
        Transformation: yes
        Interpolation: B-Spline Interpolation


        loading: E:/rcal/OUTPUT11.sdat



        Driver: SAGA

        Bands: 1

        Rows: 177

        Columns: 139



        Transformation:

        x' = 381422.717257 + x * 5.000000 + y * 0.000000

        y' = 433062.210367 + x * 0.000000 + y * -5.000000


        loading band [1/1]



        Parameters


        Grids: 1 object (OUTPUT11)
        Files: E:/rcal/OUTPUT22.sdat
        Transformation: yes
        Interpolation: B-Spline Interpolation


        loading: E:/rcal/OUTPUT22.sdat



        Driver: SAGA

        Bands: 1

        Rows: 177

        Columns: 139



        Transformation:

        x' = 381422.717257 + x * 5.000000 + y * 0.000000

        y' = 433062.210367 + x * 0.000000 + y * -5.000000


        loading band [1/1]



        Parameters


        Grids: 1 object (OUTPUT22)
        Files: E:/rcal/OUTPUT11.sdat
        Transformation: yes
        Interpolation: B-Spline Interpolation


        loading: E:/rcal/OUTPUT11.sdat



        Driver: SAGA

        Bands: 1

        Rows: 177

        Columns: 139



        Transformation:

        x' = 381422.717257 + x * 5.000000 + y * 0.000000

        y' = 433062.210367 + x * 0.000000 + y * -5.000000


        loading band [1/1]



        Parameters


        Grids: 1 object (OUTPUT11)
        Files: E:/rcal/OUTPUT22.sdat
        Transformation: yes
        Interpolation: B-Spline Interpolation


        loading: E:/rcal/OUTPUT22.sdat



        Driver: SAGA

        Bands: 1

        Rows: 177

        Columns: 139



        Transformation:

        x' = 381422.717257 + x * 5.000000 + y * 0.000000

        y' = 433062.210367 + x * 0.000000 + y * -5.000000


        loading band [1/1]



        Parameters


        Grids: 1 object (OUTPUT22)
        Files: E:/rcal/OUTPUT22.sdat
        Transformation: yes
        Interpolation: B-Spline Interpolation


        loading: E:/rcal/OUTPUT22.sdat



        Driver: SAGA

        Bands: 1

        Rows: 177

        Columns: 139



        Transformation:

        x' = 381422.717257 + x * 5.000000 + y * 0.000000

        y' = 433062.210367 + x * 0.000000 + y * -5.000000


        loading band [1/1]



        Parameters


        Grid system: 5; 177x 139y; 381425.217257x 432369.710367y
        Grids: 7 objects (OUTPUT33, OUTPUT33, OUTPUT33, OUTPUT33, OUTPUT33, OUTPUT33, OUTPUT33)
        Sum: Sum





        Error: >> WKT: unknown projection [Double_Stereographic]
        Error: >> WKT: unknown projection [Double_Stereographic]

        C:\PROGRA~1\QGIS2~1.18\bin>exit

1 Answer 1

4

If we look for the parameters used for the saga:gridssum algorithm:

>>>import processing
>>>processing.alghelp('saga:gridssum')
ALGORITHM: Rasters sum
    GRIDS <ParameterMultipleInput>
    RESULT <OutputRaster>

We can see that the GRIDS parameter has a multiple input requirement.


So instead of entering a list, we could just split the items in the list and enter them:

s1 = "E:/rcal/OUTPUT11.sdat"
s2 = "E:/rcal/OUTPUT22.sdat"
s3 = "E:/rcal/OUTPUT33.sdat"

my_list = [s1,s2,s3]
result = processing.runalg('saga:gridssum', ";".join(my_list), None)

Note: don't use list as a variable name as there is already a built-in method called this :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.