3

Using a QgsFeatureRequest by default will fetch all attributes (including geometry) of the features. I can use .setFlags(QgsFeatureRequest.NoGeometry) to not fetch the geometry, and .setSubsetOfAttributes(['value'], vector_layer.fields()) to fetch only one attribute.

I am using QgsFeatureRequest because I need the filter setDistanceWithin(QgsGeometry, tolerance).

I would like to fetch no attributes to optimise my query as I only need the id of the features.

1
  • Can you please explain your problem/question more in details? Because @BERA's solution, I assumed, is what you are looking for.
    – Taras
    Mar 7 at 12:26

1 Answer 1

1

https://api.qgis.org/api/classQgsFeatureRequest.html#a85f831f339a9882822d5d5cf19b29fdf indicates that "An empty attributes list indicates that no attributes will be fetched".

That means by combining .setFlags(QgsFeatureRequest.NoGeometry) and .setSubsetOfAttributes([]) you should receive Features that are little more than their IDs.

1
  • 1
    I had somehow missed that in the api, this is what i was looking for and probably can't be improved on as it is a hint for the data provider and so is optimised at this level, except if there are more costly data than just attributes and geometry.
    – persephone
    Mar 7 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.