I created a simple pyqgis standalone script and I have some errors with some datasets and I don't know why some times the script works fine and other times the script gives an error :

TypeError: 'NoneType' object has no attribute '__getitem__'

that is because SAGA algorithm SAGA FLOW WIDTH AND SPECIFIC CATCHMENT AREA 1 don't work correct for some datasets for other raster datasets work fine and I don't know why with the half dataset work and other not working.

and specific message in pycharm :

..\..\..\..\..\src\core\qgsmessagelog.cpp(45) : (QgsMessageLog::logMessage) [31ms] 2017-11-01T00:03:06 Processing[1] Unable to execute algorithm
Input layers do not have the same grid extent.
Unable to execute algorithm
Input layers do not have the same grid extent.

all dataset is in some srs.

I think so and for other SAGA algorithm I have similar problem .

here code :

from __future__ import unicode_literals
import qgis
from qgis.core import QgsApplication,QgsRasterLayer
import sys
qgs = QgsApplication([], False)
QgsApplication.setPrefixPath("C:/OSGeo4W64/apps/qgis-ltr", True)
import processing
from processing.core.Processing import Processing
rasterLyr = QgsRasterLayer(dem_uri, 'spi')
outputs_GDALOGRSLOPE_1 = processing.runalg('gdalogr:slope', rasterLyr, 1.0, True, True, False, 1.0, None)
rasterLyr1 = QgsRasterLayer(outputs_GDALOGRSLOPE_1['OUTPUT'], 'spi1')
outputs_SAGAFLOWWIDTHANDSPECIFICCATCHMENTAREA_1 = processing.runalg  ('saga:flowwidthandspecificcatchmentarea',rasterLyr,outputs_SAGACATCHMENTAREA_1  ['CAREA'],0, None, None)

some messages in pycharm editor :


Grids: No objects
Files: "C:path/to/image.tif"
Transformation: yes
Interpolation: Nearest Neighbor

loading: C:path/to/image.tif

Driver: GTiff
Bands: 1
Rows: 2523
Columns: 3864


x' = 393.147600 + x * 15.000000 + y * 0.000000

y' = 4564.500000 + x * 0.000000 + y * -15.000000

warning: top-to-bottom and left-to-right cell sizes differ.
using cellsize: 15.000000

C:\Users\username\PycharmProjects\ungdal>saga_cmd ta_hydrology "Catchment Area (Parallel)"  -ELEVATION "C:\Users\usernamen\AppData\Local\Temp\processing7d1c790b04654237b47a304b19a97535\dec292515b8d4b25864383e8cd17f368\C:pathtoimagetif.sgrd" -Method 0 -CAREA "C:\Users\username\AppData\Local\Temp\processing7d1c790b04654237b47a304b19a97535\ece26af68ad042bc8a77aa7665ec6cff\CAREA.sdat"

library path:   C:\OSGeo4W64\apps\saga\modules\ta_hydrology.dll
library name:   Terrain Analysis - Hydrology
tool name   :   Catchment Area (Parallel)
author      :   O.Conrad (c) 2001-2010, T.Grabs portions (c) 2010

Load grid: C:\Users\username\AppData\Local\Temp\processing7d1c790b04654237b47a304b19a97535\dec292515b8d4b25864383e8cd17f368\


Grid system: 15; 252x 385y; 3933.647600x 4506.000000y
Elevation: C:pathtoimagetif
Sink Routes: <not set>
Weight: <not set>
Material: <not set>
Target: <not set>
Catchment Area: Catchment Area
Catchment Height: <not set>
Catchment Slope: <not set>
Total accumulated Material: <not set>
Accumulated Material from _left_ side: <not set>
Accumulated Material from _right_ side: <not set>
Step: 1
Catchment Aspect: <not set>
Flow Path Length: <not set>
Method: Deterministic 8
Linear Flow: no
Linear Flow Threshold: 500.000000
Linear Flow Threshold Grid: <not set>
Channel Direction: <not set>
Convergence: 1.100000

error message:

..\..\..\..\..\src\core\qgsmessagelog.cpp(45) : (QgsMessageLog::logMessage) [31ms] 2017-11-01T00:03:06 Processing[1] Unable to execute algorithm
Input layers do not have the same grid extent.
Unable to execute algorithm
Input layers do not have the same grid extent.

any idea how to fix that using python or pyqgis ?some pythonic way to avoid this errors ?

  • related to gis.stackexchange.com/questions/124728/… Nov 1, 2017 at 14:41
  • @HugoRoussaffa-GeoDatup I have read this post that solution is from SAGA gui I know how to do that using SAGA GUI my question is how to do this using python or pyqgis in standalone pyqgis script.that is a frequency problem using saga tools in pyqgis all we need to find some common solution to fix this problem
    – Mar
    Nov 1, 2017 at 18:18
  • Why don't use the corresponding processing algorithm ? doc Nov 1, 2017 at 18:37
  • @HugoRoussaffa-GeoDatup corresponding processing algorithm ?what is this ?
    – Mar
    Nov 1, 2017 at 22:56
  • the link was not clearly visible, sorry : docs.qgis.org/2.18/en/docs/user_manual/processing_algs/saga/… Nov 2, 2017 at 5:35


Your Answer

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

Browse other questions tagged or ask your own question.