2

I want to change Color rendering of the XYZ tile(namely google satellite). In case of raster image we can easily convert using following code.

layer = iface.activeLayer()
myGrayRenderer = QgsSingleBandGrayRenderer(layer.dataProvider(),1)
layer.setRenderer(myGrayRenderer)

But this does not seems work with XYZ tile.

1 Answer 1

5
+100

Use the QgsHueSaturationFilter class:

layer = iface.activeLayer()
huesat = QgsHueSaturationFilter()
huesat.setGrayscaleMode(1)

layer.pipe().set(huesat)
layer.triggerRepaint()

Documentation : QgsHueSaturationFilter PyQGIS class

1
  • Code worked perfectly. Thank You.
    – Devenepali
    Commented Jul 28, 2022 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.