I want to make a rule-based style on the maximum value from a field. I set my expression like:
It returns every value instead of only the maximum one.
Can anyone tell me the right syntax for this?
Since QGIS 2.16 there is now an inbuilt way to calculate the maximum value for a whole layer:
This will return the largest value in the 'fieldname' column for the layer.
The max function doesn't operate across features, just values passed to the function. Eg
Will return 5. There's no function currently available which calculates the maximum value for an attribute across the entire layer.
This code, in Python Console of QGIS, returns maximum value of field whose index is 3: 'AREA' (shapefile used: world_borders.zip):
layer = iface.activeLayer() id_att_list = layer.pendingAllAttributesList() print id_att_list #list of attributes index for item in id_att_list: #index and field names print item,layer.attributeDisplayName(item) #maximum value for field whose index is 3 (AREA) area_max = layer.maximumValue(3) print "maximum area = ", area_max