[QGIS-Developer] Concatenating QgsFeatureRequest

Etienne Trimaille etienne.trimaille at gmail.com
Tue Dec 19 07:44:42 PST 2017


Hi,

You should have a look to the blog post from Nyall:
http://nyalldawson.net/2016/10/speeding-up-your-pyqgis-scripts/
So you can still use your `setFilterExpression`

1
2
3
request =
QgsFeatureRequest().setFilterFids(vector_layer.selectedFeaturesIds())
for feature in vector_layer.getFeatures(request):
    # do something with the feature


2017-12-19 16:41 GMT+01:00 Matthias Kuhn <matthias at opengis.ch>:

> Hi Matteo,
>
> No, it's not possible to combine the two in the query itself.
>
> But sending the request with the filter expression and then checking if
> each feature's id is in selectedFeatureIds() should be straightforward.
>
> selcted_ids = layer.selectedFeatureIds()
> for feature in layer.getFeatures(request):
>     if feature.id() in selected_ids:
>         do_amazing_stuff_with(feature)
>
> Matthias
>
> On 12/19/2017 04:33 PM, matteo wrote:
> > Hi devs,
> >
> > maybe the question can sound trivial but I didn't find a solution.
> >
> > Simply I would like to iterate only on selected features of a vector
> > layer features with an expression.
> >
> > I know that the QgsFeatureRequest can be used with `setFilterExpression`
> > and `setFilterFids`.
> >
> > Is it possible to combine them, so merging the following example in an
> > unique request?
> >
> > exp = ''' "PH" > 7 '''
> > request = QgsFeatureRequest().setFilterExpression(exp)
> > l = [i.id() for i in vl.selectedFeatures()]
> > request = QgsFeatureRequest().setFilterFids(l)
> >
> > for i in vl.getFeatures(request):
> >     ......
> >
> >
> > Thanks for all the suggestions!
> >
> > Cheers
> >
> > Matteo
> > _______________________________________________
> > 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
> >
> _______________________________________________
> 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/20171219/02df0223/attachment-0001.html>


More information about the QGIS-Developer mailing list