The following piece of code works well in QGIS 2, however, it does not work in QGIS 3.
myDir = 'd:/work/output_folder/'
layers = iface.legendInterface().layers()
pipe = QgsRasterPipe()
for layer in layers:
extent = layer.extent()
width, height = layer.width(), layer.height()
renderer = layer.renderer()
provider = layer.dataProvider()
crs = layer.crs().toWkt()
pipe.set(provider.clone())
pipe.set(renderer.clone())
opts = ["COMPRESS=LZW"]
file_writer = QgsRasterFileWriter(myDir + layer.name() + ".tif")
file_writer.setCreateOptions(opts)
file_writer.writeRaster(pipe, width, height, extent, layer.crs())
This is the error I get when I run the code:
Traceback (most recent call last):
File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\code.py", line 91, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
AttributeError: 'QgisInterface' object has no attribute 'legendInterface'
Does someone know what has replaced legendInterface
in the new version or what other changes I might have to make to get this to run in QGIS 3?