[QGIS-Developer] Concatenating QgsFeatureRequest

Matthias Kuhn matthias at opengis.ch
Tue Dec 19 07:41:09 PST 2017


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
> 


More information about the QGIS-Developer mailing list