[QGIS-Developer] Vector destination vs feature sink
Anita Graser
anitagraser at gmx.at
Sun Oct 23 11:30:01 PDT 2022
Thank you Matthias, those future optimization possibilities sound really exciting.
Based on all your responses so far, I think I'd summarize that Processing script developers should always go for the feature sink parameter QgsProcessingParameterFeatureSink.
Given the info Nyall shared with me, the vector destination parameter is only used in implementations of third party tools (such as Saga/grass/otb) which are limited to outputting "plain old vector files". That's why the QgsProcessingParameterVectorDestination class exists.
This has been very helpful. I'll go update my materials accordingly. Thank you all.
Regards,
Anita
On Sunday, 23. October 2022 15:45:30 (+02:00), Matthias Kuhn wrote:
Hi Anita,
A QgsFeatureSink is an interface for accepting features. This can be a QgsVectorLayer but does not have to be one. It can also be a spatial index, a vector file writer or others.
I.e. your algorithm specifies that it produces "features" which can be sent to a vector layer, another algorithm or [you-name-it]. It doesn't care if it's a vector layer, which also has other properties like style.
This even leaves room for future optimization of processing pipelines, for example, features could be sent through various algorithms without waiting for the first one to be finished.
I hope that sheds some light
Matthias
On Sun, Oct 23, 2022 at 1:48 PM Anita Graser via QGIS-Developer <qgis-developer at lists.osgeo.org> wrote:
Thank you very much, Thomas. This code comparison approach is very useful indeed.
If FeatureSink covers all functions of VectorDestination and more, that still leaves me wonder what is the downside of a FeatureSink
"Note: Consider using the more flexible QgsProcessingParameterFeatureSink wherever possible."
i.e. where is it not possible to use a Feature Sink? Only in older versions of QGIS?
Regards,
Anita
On Saturday, 22. October 2022 23:32:11 (+02:00), Thomas Gratier wrote:
Hi,
Although, I do know the intend to recommend one against the other, doing some code differences helps to sort out things.
They both inherits from same classes but the constructor for QgsProcessingParameterFeatureSink accepts an additionnal arg bool supportsAppend=false
You also find the additional methods in QgsProcessingParameterFeatureSink to manipulate the same supportsAppend.
```
a = QgsProcessingParameterVectorDestination(
'OUTPUT',
'Sortie'
)
b = QgsProcessingParameterFeatureSink(
'OUTPUT',
'Sortie'
)
methods_a = dir(a)
methods_b = dir(b)
common_methods = set(methods_a).intersection(methods_b)
print(common_methods)
only_in_a = set(methods_a).difference(methods_b)
print(only_in_a)
only_in_b = set(methods_b).difference(methods_a)
print(only_in_b)
```
Regards
Thomas Gratier
Le ven. 21 oct. 2022 à 18:07, Anita Graser via QGIS-Developer <qgis-developer at lists.osgeo.org> a écrit :
Thank you Stefan,
I saw that note but was hoping some developer could shed light on what they mean by "more flexible" and "wherever possible". I guess otherwise it's just trial and error.
Regards,
Anita
On Wednesday, 19. October 2022 07:44:05 (+02:00), Stefan Giese (WhereGroup) wrote:
Hi Anita,
they are very similar, but the API Documentation says to QgsProcessingParameterVectorDestination: "Note: Consider using the more flexible QgsProcessingParameterFeatureSink wherever possible." (https://api.qgis.org/api/3.22/classQgsProcessingParameterVectorDestination.html#details)
Best regards
Stefan
Am 18.10.2022 um 20:35 schrieb Anita Graser via QGIS-Developer:
Hi.
Does any one of you know the real difference between QgsProcessingParameterVectorDestination versus QgsProcessingParameterFeatureSink? They seem to be used interchangably in the resources I can find.
Thank you.
Anita
_______________________________________________
QGIS-Developer mailing list
QGIS-Developer at lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
--
Mit freundlichen Grüßen
Stefan Giese
Projektleiter/Consultant
---------------------------------------------
Aufwind durch Wissen!
Jetzt neu: Web-Seminare und Online-Schulungen
bei der www.foss-academy.com
---------------------------------------------
WhereGroup GmbH
Schwimmbadstr. 2
79100 Freiburg
Germany
Tel.: +49 (0)761 / 519 102 - 61
Fax: +49 (0)761 / 519 102 - 11
stefan.giese at wheregroup.com
www.wheregroup.com
Geschäftsführer:
Olaf Knopp, Peter Stamm
Amtsgericht Bonn, HRB 9885
--
--
Anita Graser
Home: http://anitagraser.com
Twitter: @underdarkgis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20221023/3fdab5e0/attachment-0001.htm>
More information about the QGIS-Developer
mailing list