示例#1
0
def mkRasterShader(layer,
                   color_ramp,
                   classif_mode=QgsColorRampShader.Continuous):
    min, med, max = getValuesFromLayer3(layer)
    rasterShader = QgsRasterShader(minimumValue=min, maximumValue=max)
    colorRamp = getRandomSingleColorRamp()
    if not color_ramp:
        utils.internal_error("Could not create color ramp")
    colorRampShader = QgsColorRampShader(minimumValue=min,
                                         maximumValue=max,
                                         colorRamp=color_ramp,
                                         classificationMode=classif_mode)
    colorRampShader.classifyColorRamp(band=1, input=layer.dataProvider())
    if colorRampShader.isEmpty():
        utils.internal_error("Empty color ramp shader")
    rasterShader.setRasterShaderFunction(colorRampShader)
    return rasterShader