rasterlayer = QgsRasterLayer(infilename, layername) renderer = rasterlayer.renderer()
rasterlayer is the active layer with renderer type is Palette, I want to get current Palette Color, how could I do? Is the Attribute in renderer?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
You can get it with .getRgb() method of QColor object:
rgb_color = renderer.legendSymbologyItems()[-1].getRgb()
This will return you a tuple with (red, green, blue, transparency) values.
renderer.legendSymbologyItems()[-1] returns you the last class from your palette as a tuple with its (name, PyQt5.QtGui.QColor) values.
P.S. there are also
.getCmyk() and a couple more methods at your service.