[QGIS-Developer] (Postgis)VectorLayer based on QgsFeatureRequest?

JD L jdaniel.lomenede at gmail.com
Mon Jan 11 06:44:33 PST 2021


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 <rdmailings at duif.net> 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
> _______________________________________________
> 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/20210111/d0177994/attachment.html>


More information about the QGIS-Developer mailing list