I have 24 layers I want to save on QGIS which all happen to be Tiff files (rasters). I am wondering how to run code to complete this task.
myDir = 'C:\temp'
layers = layers = iface.mapCanvas().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())
file_writer = QgsRasterFileWriter("%s\\%s.tif" %(myDir, layer.name() ))
file_writer.writeRaster(pipe,
width,
height,
extent,
layer.crs())
This is the code I have currently to try and run.
file_writer = QgsRasterFileWriter(myDir + layer.name() + ".tif")
with a missing "\" I would useQgsRasterFileWriter("%s\\%s.tif" %(myDir, layer.name() ))
insteadprint "%s\\%s.tif" %(myDir, layer.name() )
inside your loop to see exactly what the paths look like?