[Qgis-user] Puzzling error messages when using Processing in a Python script

Stephen Bosch posting at vodacomm.ca
Tue Nov 14 07:07:50 PST 2017


Hi everybody,

I've written a long Python script to batch-process and compute a series of
raster layers. The script is written to run entirely outside of QGIS, which
I accomplish by importing the required  modules.

I use the processing toolbox for a number of operations, for example:

processing.runalg("grass7:r.buffer",input_layer,mg_buf,1,False,clipped_extent,0,output_layer)

For some layers, I get error messages like this:

ERROR 1: /home/user/Output/masks/mgrid_mask_buffer.tif, band 1: Failed to
compute statistics, no valid pixels found in sampling.

I used a debugger and went down as many levels as it would let me. The
error occurs when QgsRasterLayer(uri, name) is called in
/usr/share/qgis/python/plugins/processing/tools/dataobjects.py:266.

The layer in question is an eight-bit unsigned integer GeoTIFF with pixels
that are either 1 or NoData (NoData value is 255).

One might think that the GeoTIFF is the problem. However, when I open the
very same file in QGIS, I get no such error. This is true even if I use the
Python console within QGIS, set the variables in question, and run the
command
processing.runalg("grass7:r.buffer",input_layer,mg_buf,1,False,clipped_extent,0,output_layer)

Overall, my experience with the Processing toolbox has been frustrating.
It's not that I expect things to work perfectly, I understand that
open-source software is a work in progress and supporting a great variety
of external libraries and third-party software such as GDAL, GRASS and SAGA
in a unified way is no easy task.

But it is a mistake to obfuscate or block error messages. These are
essential for troubleshooting. I've invested days of development time
hunting for bugs that result in part from silent failures that result in
later errors that are totally misleading. Had the original error been
presented unadulterated right at the moment when it occurred, the cause
could have been resolved in a few minutes.

(My impression that, in an effort to make QGIS "user-friendly" and avoid
confusing beginners and laypeople, aspects critical to a professional are
hidden. At the very least it should be a simple matter to turn such
functionality on.)

I understand that the bulk of development effort is going into QGIS 3. Have
these aspects been considered? I'm referring specifically to code
transparency. QGIS really should pass on error messages originating from an
external module, tell the user in which module the error occurred, and
provide both the command that was issued and the output returned (I know
that the log messages panel already does this to some extent, but why
doesn't processing.runalg, for example?)

Having said all that, I do appreciate all the development effort that has
gone and is going into QGIS. Thank you.

Kind regards

Stephen Bosch
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20171114/77e57a47/attachment.html>


More information about the Qgis-user mailing list