In QGIS 2.18 I'm try to sort features by an integer attribute with a Python script. The problem is, that some of the values of the sorting attribue are <= 0 (for sure they have to be <=0) and these features are ignorded in the sorting. How do I have to change the syntax to be sure, that also features with attribute [1] <= 0 are placed on the very first places of the table?

for feature in layer.getFeatures():
    count = layer.featureCount()
    geom = feature.geometry()
    attr = feature.attributes()

features = sorted(layer.getFeatures(),key = lambda feature: feature[1])
layer_provider = layer.dataProvider()
  • 1
    i have found the mistake: i do another sorting over an other attribute later in the script and there the sorting was damaged - only in this special cases. So finaly sorting with numbers <=0 is working. – tomzappa Sep 24 '18 at 12:17