I have to apply style(qml file) to raster . I am doing this with Qgis processing script ,
import processing
input ='E:/data/input.tif'
style_layer='E:/data/newStyleqgis.qml'
output_file = 'E:/data/abcde.tif'
processing.runalg("qgis:setstyleforrasterlayer", input,style_layer)
but their is not a option to generate output, style is set but not applied.
ALGORITHM: Set style for raster layer
INPUT <ParameterRaster>
STYLE <ParameterFile>
OUTPUT <OutputRaster>
is their any option to save it with the style loaded raster or to pass output as a parameter ,so it will save at path specified. Using the script from c# program.
Updates Script :
from PyQt4.QtCore import *
from qgis.core import *
import qgis.utils
import processing
layer = "E:/data/abc.tif"
output = "E:/data/xyz.tif"
fileInfo = QFileInfo(layer)
baseName = fileInfo.baseName()
filename ='abc.tif'
rlayer = QgsRasterLayer(filename, baseName)
# Define the minimum extent of the region
style_layer='E:/data/newStyleqgis.qml'
processing.runalg("qgis:setstyleforrasterlayer", layer, style_layer)
extent = rlayer.extent()
xmin = extent.xMinimum()
xmax = extent.xMaximum()
ymin = extent.yMinimum()
ymax = extent.yMaximum()
width = rlayer.width()
height = rlayer.height()
renderer = rlayer.renderer()
provider= rlayer.dataProvider()
crs = rlayer.crs().toWkt()
pipe = QgsRasterPipe()
pipe.set(provider.clone())
pipe.set(renderer.clone())
file_writer = QgsRasterFileWriter(output)
file_writer.writeRaster(pipe,width,height,extent,layer.crs())
showing error :NoneType' object has no attribute 'clone'
Singleband gray. – Joseph Dec 01 '16 at 10:29extent = layer.extent() but i am not loading layer in qgis . i am doing the process from standalone script using proceesing .
– User18 Dec 01 '16 at 11:32