下面的代码在QGIS 2.x中运行良好,但是在QGIS 3.x中不起作用。
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())
这是我运行代码时遇到的错误:
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'
有人知道新版本中替换了'legendInterface'的内容还是要使其在QGIS 3.0中运行可能需要做哪些其他更改?