[QGIS-Developer] Programmatically iterate over features with Processing in QGIS 3

DelazJ delazj at gmail.com
Fri Sep 14 23:36:17 PDT 2018


Hi,

Thanks Nyall. If it uses the same getFeatures method (already shown
multiple times) then I'll remove that example.

Regards,
Harrissou


Le ven. 14 sept. 2018 à 01:59, Nyall Dawson <nyall.dawson at gmail.com> a
écrit :

> On Thu, 13 Sep 2018 at 15:40, DelazJ <delazj at gmail.com> wrote:
> >
> > Hi,
> > CCing to qgis-dev as nobody in community seems... inspired by the
> question and I'd like to close that old PR and rebase other changes.
> >
> > Thanks for any hint.
> >
> > Harrissou
> >
> > Le mar. 11 sept. 2018 à 18:12, DelazJ <delazj at gmail.com> a écrit :
> >>
> >> Hi all,
> >>
> >> QGIS documentation states [0] that Processing can be used to iterate
> over features with the following code:
> >>
> >> import processing
> >> features = processing.features(layer)
> >> for feature in features:
> >>     # do whatever you need with the feature
> >>
> >> This code no longer works in QGIS3 and needs an update [1] I fail to
> find.
> >> So anyone to suggest the right replacement, please?
>
> Just iterate directly over the features from the source. The things
> which processing.features used to do is taken care of transparently
> for you now.
>
> I.e.
>
>     source = self.parameterAsSource(parameters, 'INPUT', context)
>     for f in source.getFeatures():
>        # do something with f
>
> As much as possible, Processing-specific methods were removed in QGIS
> 3.0 in favour of the standard PyQGIS calls. This was done to reduce
> code duplication, and make the API more consistent (i.e. easier to
> move code between Processing algorithms -> standalone scripts/plugins
> and vice versa).
>
> Nyall
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20180915/d9bcbee8/attachment.html>


More information about the QGIS-Developer mailing list