I'm having a bit of a trouble migrating an algorithm from pyqgis 2 to pyqgis 3. The thing is I want to make visible and invisible a series of layers as I iterate through a list and render some images.
A little more explanation: I have this big python list which contains several dictionaries. Each item of the list contains a series of "actions" I need to perform in order to render some images with a specific configuration. One of this possible actions is turning on or off a layer's visibility (and eventually the Google Maps Raster). So, in my code what I'm trying to implement is some function like this:
def __layer_actions(actions): for action in actions: if action["type"] == "layer_opacity": get_layer(action["layer"]).setOpacity(action["opacity"] / 100) if action["type"] == "layer_visibility": if(action["visibility"] is True): get_layer(action["layer"]).draw() # fails when the layer is actually a raster
Since the Raster's draw function is not the same as the layer's one, when I'm processing a Raster I get this error:
TypeError: QgsRasterLayer.draw(): not enough arguments
How can I rearrange things to contemplate this case in which my code is failing? For example, if I could just manage to turn the Raster's visibility on/off somehow, I could use a try/except sentence.