Hi, 

Thanks! 

My issue is not so much using the QgsFeatureRequest (and it's filters) in 
python. 
You can do a 'layer.getFeatures(request)' too.
It's more like that I think it would be nice to have some kind of 
'filtered'-layer notion, but a little more fine-grained then current 
'filter'-use.

Raymond told me that using 'Virtual Layers' it is possible to use the full 
sql-query syntax.
And I just tested and indeed that seems to work.
Have to see how this is implemented though...

Regards,

Richard Duivenvoorde

On 1/11/21 3:44 PM, JD L wrote:
> Hi Richard, 
> have you considered something like this (maybe not the optimal way)
> 
> req = QgsFeatureRequest()
> req.setLimit(10)
> 
> sink, dest = QgsProcessingUtils.createFeatureSink(
>     uri,
>     QgsProcessingContext(),
>     source_layer.fields(),
>     source_layer.wkbType(),
>     source_layer.crs()
> )
> 
> sink.addFeatures(source_layer.getFeatures(req), QgsFeatureSink.FastInsert)
> 
> del sink
> 
> Regards,
> 
> 
> Le lun. 11 janv. 2021 à 14:50, Richard Duivenvoorde <[email protected] 
> <mailto:[email protected]>> a écrit :
> 
>     Hi Devs,
> 
>     I have this project in which there is (a set of different) moving cars 
> (in time and position), but I only want to show (and able to edit in a 
> plugin) the LAST POSITION of the cars.
> 
>     In QGIS gui you can NOT use 'limit' or 'order' parts in the filter 
> clause, I can only filter on car-ID (or so) (would be nice to have I 
> think...).
> 
>     In PyQGIS you can create a featureIterator based on a QgsFeatureRequest 
> in which you CAN set limit and order of the set to iterate over...
> 
>     My question is: can I create a VectorLayer, based on a QgsFeatureRequest?
>     In this way you can (at least in python) create a much finer grained 
> 'filter' for a certain layer.
> 
>     I looked into the api and did some googling, and hope that I just missed 
> it...
> 
>     I have thought about creating a VIEW in the db for this (that is with an 
> ordering on time and limit 1), and then with a filter=xxx in QGIS gui, I can 
> at least see my subset's.
>     But I think it is actually stronger to sort of have an real (editable) 
> layer in QGIS for that?
> 
>     Regards,
> 
>     Richard Duivenvoorde
> 
>     [0] https://qgis.org/pyqgis/master/core/QgsFeatureRequest.html 
> <https://qgis.org/pyqgis/master/core/QgsFeatureRequest.html>
>     _______________________________________________
>     QGIS-Developer mailing list
>     [email protected] <mailto:[email protected]>
>     List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer 
> <https://lists.osgeo.org/mailman/listinfo/qgis-developer>
>     Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer 
> <https://lists.osgeo.org/mailman/listinfo/qgis-developer>
> 

_______________________________________________
QGIS-Developer mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to