In a standalone application, I have a layer to which I select some features. Then I need to do an iteration, and I need it to be done in the order of the value of a field/attribute (In my example order by Name of the Cities).
vLayer = QgsVectorLayer(cities_of_world_file, 'Cities of World', "ogr")
country = 'Spain'
filter = '"Country"=\'%s\' '%country
vLayer.selectByExpression(filter, QgsVectorLayer.SetSelection)
for feature in vLayer.selectedFeatures():
print(feature['City'])
I think there are two ways:
Open the layer ordered, and after that, you make a selection. In SQL when you select records you can say
ORDER BY
, is this order in aQgsVectorLayer
?Select features and after that, you sort.
How can I do this?