[QGIS-Developer] [Qgis-user] processAlgorithm vs processFeature?

C Hamilton adenaculture at gmail.com
Wed Aug 25 07:01:04 PDT 2021


Thanks everyone. I went ahead and updated the geodesic transformations tool
in Shape Tools to use the QgsProcessingFeatureBasedAlgorithm algorithm. I
didn't know that existed and I had only used QgsProcessingAlgorithm, I also
updated the geodesic transformations tool  to use data derived overrides. I
had a hard time finding documentation and python examples on how to do it,
but I believe I have it all working now.

On Wed, Aug 25, 2021 at 2:47 AM Etienne Trimaille <
etienne.trimaille at gmail.com> wrote:

> Indeed, if you can, you should use a QgsProcessingFeatureBasedAlgorithm
> algorithm. It will make some shortcuts for you and the code is shorter
> because you will only have a single feature to process.
>
> Have a look to existing source code :
> https://github.com/qgis/QGIS/search?q=QgsProcessingFeatureBasedAlgorithm
>
> Le mar. 24 août 2021 à 04:55, Ujaval Gandhi <ujaval at spatialthoughts.com>
> a écrit :
>
>> If your algorithm works on each feature independently, processFeature()
>> is preferred. If you need to work with layers, you need to use
>> processAlgorithm(). I demonstrate this with an example at
>> https://spatialthoughts.com/2019/04/05/geodesic-buffers-in-qgis/
>>
>> On Mon, 23 Aug 2021 at 10:25 PM, C Hamilton <adenaculture at gmail.com>
>> wrote:
>>
>>> I discovered that it looks like there is another way to deal with
>>> processing algorithms. Rather than use processAlgorithm it looks like I can
>>> use prepareAlgorithm & processFeature. I have always used processAlgorithm
>>> and then iterated through the features.
>>>
>>> Is processFeature just as quick as using processAlgorithm (iterating
>>> through the features)? Is one method preferred over the other? I think for
>>> some algorithms using processFeature would make the code look cleaner. Are
>>> there any gotchas in using the processFeature method?
>>>
>>> Thanks,
>>>
>>> Calvin
>>> _______________________________________________
>>> Qgis-user mailing list
>>> Qgis-user at lists.osgeo.org
>>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
>>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
>>>
>> --
>> [image: Logo] <https://spatialthoughts.com/>
>> Ujaval Gandhi
>> Spatial Thoughts
>> mobile: +91-8095684687
>> email: ujaval at spatialthoughts.com
>> [image: LinkedIn icon] <https://www.linkedin.com/in/spatialthoughts/>  [image:
>> Twitter icon] <https://twitter.com/spatialthoughts>
>>
>> _______________________________________________
>> 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
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20210825/849cc58e/attachment.html>


More information about the QGIS-Developer mailing list