3

I want to get the maximum value of the layer. (ex, 1st field)

I used the layer (or provider) maximumValue () function.

but the same value is always obtained.

ex>

There are five features and the first field value is 1, 2, 3, 4, 5.

  1. The maximumValue () function returns 5.

  2. Delete the fifth feature. The remaining features are four, and the first field value is 1,2,3,4.

  3. The maximumValue () function returns 5 equally.

I expected it to return 4.

Why does the same value get returned after the feature changes?

(commitChanges () was done.)

aLayer = QgsMapLayerRegistry.instance().mapLayersByName('aaaLayer')[0]
print aLayer.getValues('field_1')
>>> ([1, 2, 3, 4, 5], True)  --------------> field_1 value list : 1, 2, 3, 4, 5 
print aLayer.maximumValue(0)
>>> 5 -----------------------------> 1
aLayer.startEditing()
aLayer.deleteFeature(5) # ---------------> delete feature.
aLayer.commitChanges()
print aLayer.getValues('field_1')
>>> ([1, 2, 3, 4], True)  ------------------> field_1 value list : 1, 2, 3, 4
print aLayer.maximumValue(0)
>>> 5  ------------------------------> 2

Why are 1 and 2 the same?

How can I solve it?

closed as unclear what you're asking by PolyGeo Feb 13 '18 at 21:14

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Are you sure that the feature ID 5 is the one having the field_1 value 5? You might be deleting another one... – JGH Feb 13 '18 at 16:15
  • 2
    Which QGIS version and platform are you using? This works fine for me on an integer field (QGIS 2.18.14 for Win7 64-bit). – Joseph Feb 13 '18 at 17:29
  • Thank you. 2.12 32bit is being used. It works correctly in 2.18. – kaslim Feb 14 '18 at 7:34

Browse other questions tagged or ask your own question.