[QGIS-Developer] Vector destination vs feature sink

Matthias Kuhn matthias at opengis.ch
Sun Oct 23 06:45:30 PDT 2022


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
> <https://api.qgis.org/api/3.22/classQgsProcessingParameterFeatureSink.html> 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
> <https://api.qgis.org/api/3.22/classQgsProcessingParameterFeatureSink.html#acae2863d5dab37aec4c5466d7d3a84d9>
> =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
>> <https://api.qgis.org/api/3.22/classQgsProcessingParameterFeatureSink.html>
>> 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 listQGIS-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.comwww.wheregroup.com
>> Geschäftsführer:
>> Olaf Knopp, Peter Stamm
>> Amtsgericht Bonn, HRB 9885
>>
>>
> --
> --
> Anita Graser
> Home: http://anitagraser.com
> Twitter: @underdarkgis
>
> _______________________________________________
> 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
>

-- 
 <https://qfield.org/get/>

QFIELD 2.0 IS HERE! - Hold the power of QGIS in 
your hand - learn more 
<https://www.opengis.ch/2022/04/05/qfield-2-0-is-here/> - get it now 
<https://qfield.org/get>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20221023/37aad128/attachment.htm>


More information about the QGIS-Developer mailing list