I am trying to find the python equivalent of enabling the checkbox for controlling the feature rendering order based on an attribute of the features of a layer (see below screenshot).
I want to base the rendering order on 'height' as shown in the screenshot.
My code below reads:
lyr_features = sorted(lyr_features, key = lambda i: i['height'])
colours = self.linear_gradient(len(lyr_features))
for i, feat in enumerate(lyr_features):
myMin = feat['height']
myMax = feat['height'] + 0.5
myLabel = '{}'.format(feat['height'])
myColour = QtGui.QColor(str(colours[i]))
mySymbol = QgsSymbol.defaultSymbol(lyr.geometryType())
mySymbol.setColor(myColour)
mySymbol.setOpacity(myOpacity)
myRange = QgsRendererRange(myMin, myMax, mySymbol, myLabel)
myRangeList.append(myRange)
myRenderer = QgsGraduatedSymbolRenderer('', myRangeList)
myRenderer.setMode(QgsGraduatedSymbolRenderer.Pretty)
myStyle = QgsStyle().defaultStyle()
defaultColorRampNames = myStyle.colorRampNames()
ramp = myStyle.colorRamp(defaultColorRampNames[25])
myRenderer.setSourceColorRamp(ramp)
myRenderer.setClassAttribute(myTargetField)
lyr.setRenderer(myRenderer)
QgsProject.instance().addMapLayer(lyr)
lyr.triggerRepaint()
This is okay, but I then need to manually go in and enable the feature rendering control. Maybe something like this:
myRenderer.orderByEnabled(True)
This doesn't work but maybe along the lines of this?
setOrderByEnabled