[QGIS-Developer] Example script for Processing in QGIS 3

Nyall Dawson nyall.dawson at gmail.com
Fri Jan 26 15:39:50 PST 2018


On 27 January 2018 at 05:33, Anita Graser <anitagraser at gmx.at> wrote:
>
>
> On Tue, Jan 23, 2018 at 12:14 PM, G. Allegri <giohappy at gmail.com> wrote:
>>
>> Hi Nyall,
>> scripts seem way more complex then before. I guess it is the simplest way
>> that could be found to accomodate Processing scripts to the refactored code.
>> Some questions from the previous scripts examples:
>>
>> 1) Is automatic output / sink parameter conversion impossible to obtain?
>> In [1] self.parameterAsSink is used, and it's not very clear to me what the
>> second method output (Biggest_parts) represent. Input / source (Polygons) is
>> used directly instead, as it was in QGIS 2.x
>>
>> 2) There are some global vars that appear to be automagically injected by
>> the script execution context, like "parameters" and "context". Are they
>> documented somewhere?
>>
>> 3) The test scripts use different approaches. Centroids.py use source /
>> sink, while the others two define vector / vectorDestination. Are they
>> supposed to work?
>
>
> I'd like to second Giovanni's questions. The current situation is a bit
> confusing and looks considerably more complex than the previous
> implementation.

I struggled with this API, and it's the best I could come up with at
the time. I'm more than happy if someone submits a PR to improve this.

(Same with https://github.com/qgis/QGIS/pull/4841 - can we get a
volunteer to take over this and get it merged? Honestly, our
regression list is still long and I think my remaining time before
release is better spent tackling that. We have plenty of community
members who can write quality guides and who could chip in here -- but
the list of community members who can fix
https://issues.qgis.org/issues/17364 is rather short.)

But -- while we're at it -- am I the only one who finds processing
script files in general to be full of a lot of black magic? (Note that
I'm referring to script files here, not proper algorithms). When
refactoring processing to c++ I kept the script syntax unchanged from
2.x as much as possible (with the exception of the sinks, which I
cannot work out how to improve - save for re-creating a dummy
VectorWriter object that wraps a bunch of stuff up). But to me it's
*always* been rather un-python-like how parameters and outputs are
defined in comments, how some variables are automatically created, how
some output variables are expected, etc.

It's not too late to improve this for 3.x. Why don't we get the daily
Python users and experts involved here and come up with a more
Python-like approach to processing scripts?

Nyall


More information about the QGIS-Developer mailing list