0

My layer has an attribute 'name' which is unique for the layer and enforced by the database. I have been looking for an API call that will return a list of features that match the value of the name attribute but can't find anything.

Is there a more efficient way of finding the feature by attribute value than simply iterating over all the features in the layer?

I am guessing not since this implies QGIS maintains some form of index which I doubt!

2

1 Answer 1

1

underdark's suggestion works well and would be great for large sets of data but was only a marginaly faster for my cases where I had less than 1000 points in the layer. What I ended up doing was reading the whole layer and building a dictionary indexed by name. Once done it was very fast to find individual entries.

It worked because I was repeatedly looking for exact matches, if you want to do searches that return multiple possibilities then the filter option is better.

As usual with things like this there are tradeoffs depending on exactly what you need to do

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