Basic Processing plugin questions

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Basic Processing plugin questions

Tom Chadwin
Hello all

I'm looking at writing a Processing plugin, but I have some incredibly basic questions, as I've never really used Processing myself:

1. Can a Processing plugin only take a single layer as input, or can it take more?

2. Can a Processing plugin take *any* layer, rather than having to choose between raster and vector?

3. Must a Processing plugin output a layer?

I'm sure I'll have more, so apologies in advance.

Thanks

Tom
Reply | Threaded
Open this post in threaded view
|

Re: Basic Processing plugin questions

volaya
>
> 1. Can a Processing plugin only take a single layer as input, or can it take
> more?

It can take several one-layer parameters (so, in the end, there is a
fixed number of them), or take a multiple-layer parameter, which is a
single parameter but the user can select a list with an undetermined
number of layers (even an empty list, if allowed)
>
> 2. Can a Processing plugin take *any* layer, rather than having to choose
> between raster and vector?

No, not at the moment. The multiple input can have several layer types
at once, but single layers can't

>
> 3. Must a Processing plugin output a layer?

No. It can output layers, tables, numbers, string...in any combination
you want, just like input parameters

Hope this helps
_______________________________________________
Qgis-developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: Basic Processing plugin questions

Tom Chadwin
Thanks, Victor.

volaya wrote
> 3. Must a Processing plugin output a layer?

No. It can output layers, tables, numbers, string...in any combination
you want, just like input parameters
How about outputting nothing at all (in a Processing context, I mean)? I presume that is also acceptable? Or is the best approach in such a case to output the inputs, as it were?
Reply | Threaded
Open this post in threaded view
|

Re: Basic Processing plugin questions

Matthias Kuhn 🌍
Hi Tom

On 4/4/17 11:50 AM, Tom Chadwin wrote:

> Thanks, Victor.
>
>
> volaya wrote
>>> 3. Must a Processing plugin output a layer?
>> No. It can output layers, tables, numbers, string...in any combination
>> you want, just like input parameters
> How about outputting nothing at all (in a Processing context, I mean)? I
> presume that is also acceptable? Or is the best approach in such a case to
> output the inputs, as it were?

just for my understanding, can you shortly explain the use-case?

Thanks
Matthias
_______________________________________________
Qgis-developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: Basic Processing plugin questions

volaya
>> How about outputting nothing at all (in a Processing context, I mean)? I
>> presume that is also acceptable? Or is the best approach in such a case to
>> output the inputs, as it were?

Depends on the algorithm. If the algorithm modifies a layer, it is a
good idea to output that same layer, so then it can be linked to a new
algorithm in the modeler. If your algorithm does something that doesn
not "produce" anything at all (for instance, the GeoServer pluin has
Processing algs to deploy a layer to a GeoServer instance), then it's
ok to not have any output

Both options are accepted by the Processing syntax
_______________________________________________
Qgis-developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: Basic Processing plugin questions

Tom Chadwin
Thanks, Victor - clear as a bell.

Tom
Reply | Threaded
Open this post in threaded view
|

Re: Basic Processing plugin questions

Tom Chadwin
In reply to this post by volaya
volaya wrote
> 2. Can a Processing plugin take *any* layer, rather than having to choose
> between raster and vector?

No, not at the moment. The multiple input can have several layer types
at once, but single layers can't
Can it? If I add a multiple input, the dropdown only contains my project's point (vector) layers. If I explicitly set the datatype for the ParameterMultipleInput to -1 (see https://github.com/qgis/QGIS/blob/master/python/plugins/processing/tools/dataobjects.py#L53), the dropdown correctly contains all my vector layers (point, line, and poly).

What I was hoping for is to able to take *any* layer - vector or raster. However, datatype ALL_TYPES (defined as [-1] at https://github.com/qgis/QGIS/blob/master/python/plugins/processing/tools/dataobjects.py#L51) fails, as it won't accept a list:

File "C:/OSGEO4~1/apps/qgis/./python/plugins\processing\core\parameters.py", line 362, in __init__
                            self.datatype = int(float(datatype))
                        TypeError: float() argument must be a string or a number

I'm clearly not quite understanding this yet. Can anyone help?

Thanks

Tom
Reply | Threaded
Open this post in threaded view
|

Re: Basic Processing plugin questions

volaya
mmm, it should accept a list. That should be fixed, then

2017-04-05 15:02 GMT+02:00 Tom Chadwin <[hidden email]>:

> volaya wrote
>>> 2. Can a Processing plugin take *any* layer, rather than having to choose
>>> between raster and vector?
>>
>> No, not at the moment. The multiple input can have several layer types
>> at once, but single layers can't
>
> Can it? If I add a multiple input, the dropdown only contains my project's
> point (vector) layers. If I explicitly set the datatype for the
> ParameterMultipleInput to -1 (see
> https://github.com/qgis/QGIS/blob/master/python/plugins/processing/tools/dataobjects.py#L53),
> the dropdown correctly contains all my vector layers (point, line, and
> poly).
>
> What I was hoping for is to able to take *any* layer - vector or raster.
> However, datatype ALL_TYPES (defined as [-1] at
> https://github.com/qgis/QGIS/blob/master/python/plugins/processing/tools/dataobjects.py#L51)
> fails, as it won't accept a list:
>
> File "C:/OSGEO4~1/apps/qgis/./python/plugins\processing\core\parameters.py",
> line 362, in __init__
>                             self.datatype = int(float(datatype))
>                         TypeError: float() argument must be a string or a number
>
> I'm clearly not quite understanding this yet. Can anyone help?
>
> Thanks
>
> Tom
>
>
>
> -----
> Buy Pie Spy: Adventures in British pastry 2010-11 on Amazon
> --
> View this message in context: http://osgeo-org.1560.x6.nabble.com/Basic-Processing-plugin-questions-tp5315610p5315896.html
> Sent from the QGIS - Developer mailing list archive at Nabble.com.
> _______________________________________________
> Qgis-developer mailing list
> [hidden email]
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
_______________________________________________
Qgis-developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: Basic Processing plugin questions

Tom Chadwin
OK, I've got a rough version running. Another question: any guidelines on appropriate values for:

- provider name (myProvider.getName())
- provider description (myProvider.getDescription())
- algorithm name (myAlgorithm.name)
- algorithm group (myAlgorithm.group)

Given that this algorithm exports a webmap, is there an appropriate group already in existence? Or should I just make my own decisions? There might be multiple algorithms in my provider in the future.

Thanks

Tom

PS  Thanks to Nyall for suggesting this as an interesting project. We'll see if users actually find it useful or not...