1

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)
QgsApplication.initQgis()
sys.path.append('C:/OSGeo4W64/apps/qgis-ltr/python/plugins')
import processing
from processing.core.Processing import Processing
Processing.initialize()
rasterLyr = QgsRasterLayer(dem_uri, 'spi')
rasterLyr.isValid()
outputs_GDALOGRSLOPE_1 = processing.runalg('gdalogr:slope', rasterLyr, 1.0, True, True, False, 1.0, None)
rasterLyr1 = QgsRasterLayer(outputs_GDALOGRSLOPE_1['OUTPUT'], 'spi1')
rasterLyr1.isValid()
.....................................
outputs_SAGAFLOWWIDTHANDSPECIFICCATCHMENTAREA_1 = processing.runalg  ('saga:flowwidthandspecificcatchmentarea',rasterLyr,outputs_SAGACATCHMENTAREA_1  ['CAREA'],0, None, None)
.....................................

some messages in pycharm editor :

Parameters

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



Transformation:

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\
C:pathtoimagetif.sgrd...




Parameters


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 ?

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.