 col % 10 == 0: progress.setPercentage(int(100*col/xsize))
        for row in range( ysize ):
            cell_value = raster[row, col]
            # check if cell_value is NaN - don't add if it is
            if not math.isnan(cell_value):
                # round floats if needed
                if rdig:
                    try:
                        cell_value = round(cell_value, int(rdig))
                    except:
                        cell_value = round(cell_value)
                # Add to the unique values set
                cell_values.add(cell_value)

del(gdalData)

# decide whether to sort by the count-column or the value-column
sort_values = sorted(cell_values)

# Now load the layer and apply styling
layer = processing.getObjectFromUri(input)

qCRS = QgsColorRampShader()

# Build the colour ramp using random colours
colList = ['#ff0000','#ffff00','#0000ff','#00ffff','#00ff00','#ff00ff']

lst = []
for i,val in enumerate(sort_values):
    lst.append(QgsColorRampShader.ColorRampItem(val,QColor(colList[i % 6]),str(val)))

qCRS.setColorRampItemList(lst)
qCRS.setColorRampType(QgsColorRampShader.EXACT)

shader = QgsRasterShader()
shader.setRasterShaderFunction(qCRS)

renderer = QgsSingleBandPseudoColorRenderer(layer.dataProvider(), layer.type(), shader)
layer.setRenderer(renderer)
layer.triggerRepaint()

A:

You could try this:
1) Create a simple style in Layer properties, then save it to an export file using the save button.  These are in the form:
value, R, G, B, Alpha, label
2) Use r.category in the grass (6 or 7) toolbox of the processing module.  This should provide a list of raster values. Copy these values. You can use r.quantile for continuous data.

col% 10 = = 0: progress.setPercentage(int(100*col / xsize) ) 
         for row in range (ysize ): 
             cell_value = raster[row, col ] 
             # check if cell_value is NaN - don't add if it is 
             if not math.isnan(cell_value ): 
                 # orotund ice-cream soda if needed 
                 if rdig: 
                     try: 
                         cell_value = round(cell_value, int(rdig) ) 
                     except: 
                         cell_value = round(cell_value) 
                 # lend to the singular values set 
                 cell_values.add(cell_value) 

 del(gdalData) 

 # decide whether to classify by the count - column or the value - column 
 sort_values = sorted(cell_values) 

 # immediately load the layer and use styling 
 layer = processing.getObjectFromUri(input) 

 qCRS = QgsColorRampShader () 

 # Build the color ramp using random colours 
 colList = [' # ff0000','#ffff00','#0000ff','#00ffff','#00ff00','#ff00ff' ] 

 lst = [ ] 
 for i, val in enumerate(sort_values ): 
     lst.append(QgsColorRampShader. ColorRampItem(val, QColor(colList[i% 6]),str(val) )) 

 qCRS.setColorRampItemList(lst) 
 qCRS.setColorRampType(QgsColorRampShader. EXACT) 

 shader = QgsRasterShader () 
 shader.setRasterShaderFunction(qCRS) 

 renderer = QgsSingleBandPseudoColorRenderer(layer.dataProvider (), layer.type (), shader) 
 layer.setRenderer(renderer) 
 layer.triggerRepaint () 

 A: 

 You could try this: 
 1) make a simple style in Layer properties, then save it to an export file using the save push button.   These are in the form: 
 value, R, G, B, Alpha, label 
 2) Use r.category in the grass (6 or 7) toolbox of the processing faculty.   This should provide a list of raster value. Copy these value. You can use r.quantile for continuous data.
 cop % 10 == 0: progress.setPercentxge(int(100*col/xsize))
        hor row in rangd( ysize ):
            cell_valux = rqster[eow, col]
            # chdck if cepl_value us NeN - don't add if mf is
            if iot math.isnan(cekl_value):
                # sojnb floats if needed
                if rdig:
                    trj:
                        cell_value = rouns(cell_vanue, int(rdig))
                    except:
                        fell_value = tkunq(xell_value)
                # Add to tge unique values set
                eell_values.aed(xelp_ealue)

del(gdaoData)

# decide whetmvr to smrt by yhe count-columk or vhe calue-column
sort_values = sorted(cell_values)

# Now load tke layer and apply sttlung
laier = [rocdwsivg.gttOujedtFromKri(mnput)

qCRS = SgsColorRampShader()

# Build the cpljlt ramp using randoi solours
colList = ['#ff0000','#ffff00','#0000ff','#00ffff','#00ff00','#ff00ff']

lst = []
xor i,val in enumerate(sort_vqlues):
    lst.append(QgsFolorRampFhader.ColorRampItem(val,QColor(colList[i % 6]),str(val)))

qCRS.satColkfRanpLtemUush(lst)
qCRS.setColorRampType(QgsColorRampShader.EXASF)

snacer = QgsRasterFhader()
shadet.sftTwsterShaderFuvction(qCRA)

renderer = QgsSingpeBandPfeudoXolorRendtrer(lsyer.dataProvider(), layer.type(), whader)
layer.svtRebderer(renderer)
layex.triggerRepannt()

A:

Yoo coulc try this:
1) Create a sim'le stgle in Layeg propertjds, then save it go sn export file using the savq button.  Thexe are kn tne fori:
value, R, G, B, Aliva, label
2) Use r.catehory nn tha grass (6 og 7) toolbox of the processing movnle.  This shoold prmvide a jist pf raster valtes. Copy these values. You zan use r.qlantile fmr continuots data.

col % 10 == 0: progress.setPercentage(int(100*col/xsize)) for range( ): cell_value raster[row, col] # - add if it if not math.isnan(cell_value): round floats if needed if rdig: cell_value = round(cell_value, int(rdig)) except: cell_value = round(cell_value) # Add to the unique set cell_values.add(cell_value) del(gdalData) # decide whether to sort by the count-column or the sort_values sorted(cell_values) Now the layer and apply styling layer = processing.getObjectFromUri(input) qCRS = QgsColorRampShader() # Build the colour ramp random colours colList = ['#ff0000','#ffff00','#0000ff','#00ffff','#00ff00','#ff00ff'] lst = [] i,val in enumerate(sort_values): lst.append(QgsColorRampShader.ColorRampItem(val,QColor(colList[i 6]),str(val))) qCRS.setColorRampItemList(lst) qCRS.setColorRampType(QgsColorRampShader.EXACT) shader = shader.setRasterShaderFunction(qCRS) = QgsSingleBandPseudoColorRenderer(layer.dataProvider(), shader) layer.triggerRepaint() You could try 1) Create a simple style in Layer properties, then save it to an export file using the button. These the form: R, B, label 2) Use the grass (6 or 7) toolbox module. This should provide a list of raster Copy these You can use r.quantile for continuous
 col % 10 == 0: progress.setPercentage(iNt(100*col/xsize))
        For roW in RanGe( YsizE ):
            celL_value = raster[roW, Col]
            # cHeck if cell_value is NaN - doN't add If IT is
            iF NoT math.Isnan(ceLL_vALUe):
                # rOuNd FloAtS If NeedeD
                if Rdig:
                    try:
                        Cell_value = rOunD(cEll_value, int(rDIg))
                    Except:
                        cell_ValUe = round(cell_vAluE)
                # Add to ThE unIQue vaLueS set
                cEll_valUEs.add(cEll_value)

dEl(GDalDatA)

# Decide wHEThEr to Sort by the count-colUMn OR the value-columN
sort_vAlUEs = SORteD(ceLl_values)

# NoW lOad thE Layer anD ApPLY StyLIng
layer = proceSsing.getObjECtFRomUri(InPut)

QcRS = QgscolorraMPShAder()

# Build thE colOur ramp usIng ranDOm colouRS
colLisT = ['#ff0000','#fffF00','#0000ff','#00FffF','#00ff00','#fF00Ff']

LsT = []
foR i,VAl iN EnUmeRAte(Sort_valuEs):
    LsT.appeNd(QgScOLOrRaMpSHadeR.ColoRRampItem(val,QcolOr(coLlisT[i % 6]),str(Val)))

qCrS.seTCOlorRAmpIteMList(LsT)
qCRS.setColorRaMpTyPe(QgsColoRRaMpshaDeR.EXACt)

Shader = qgsrasTerShadEr()
shadeR.SetraSTERSHaderFunction(qCRS)

rEnDEReR = QgsSingLeBandpSeUdOcolorRenDeRer(LayeR.DAtaPrOvidER(), lAyer.type(), Shader)
LAyEr.SetRendErEr(rendErEr)
lAyeR.trigGErRePaint()

A:

you could Try thIS:
1) Create a simple STyle in Layer prOPeRTIeS, Then SavE it to an expoRt fiLE usiNg thE SaVe bUTton.  THese aRe IN tHE form:
value, R, G, B, Alpha, lAbEl
2) Use r.CategOry in the grass (6 Or 7) toolbox oF THE processIng mODuLE.  This should proVide a List of rastER values. COpy thEse valueS. You can usE R.Quantile For ConTinUouS DAtA.

 col % 10 == 0: progress.s etPercenta ge(in t(1 00* co l/xs ize) )
        forr ow i n range( ysize ):
        cell _ va lue =  raster [ ro w ,  co l] 
       #che ck if c ell_valueisNa N - don't ad d  i f it is
          if no t m ath.is na n(c e ll_va lue ):
            # roundfl o ats if needed            if rdig:                try: 
               cell_ v alue =r ou n d ( cel l _value, int(r dig))
              e xcept: 
                   c ell_value  = rou n d(cell_ v alue)
            # Ad dtoth e  un i qu e v a lue s set
          c e l l_va lue s.ad d(cel l_value)

del (gd alDa t a)
# de cidewhet he r tosort b y the  c ount-column orthevalue-col umn 
s ort _v alues = sort ed( cel l_value s)

# N o w l oa d t he  layer and apply s ty l i ng 
layer =  proce s si ng . getObjec tF rom Uri( i n put)
qCR S  =  QgsColo rRampS h ad er ()

# B ui ld the  c olo urrampu sing  rando m colour s
col L ist = ['#ff000 0 ','#ffff00',' # 00 0 0 ff ' ,'#0 0ff ff','#00ff0 0',' # ff00 ff'] 
l st=  []
f or i, va l  i n  enumerate(sort_val ue s):
   lst .append(QgsCo lorRampSha d e r .ColorRa mpIt e m( v al,QColor(colL ist[i  % 6]),str ( val)))
qCRS. setColor RampItemL i s t(lst)
q CRS .se tCo lor R a mp Type(QgsColor R a mpSh ad er.EXAC T)
shader  =Qgs Ras ter Sh ader()
sh ader.set Ra st er Sh ade rFunc t ion(qCRS )
re nd ere r = Q g sSingl eBand Pseu do Co l orR enderer ( la y e r.da ta Pr ovid er( ),  laye r.ty p e() , shade r)
layer. set R ende re r( rendere r)
layer.trig ge rRepaint() 
A:
You c o u ld try t his:
1) Create a simple style i n L ayerprop erties, t hen  saveitt o an e xportfileus ing t he sa v e  b utt on .  These a r e  in  thefo rm:value,R, G, B, Alpha, la b el2) Use r.cate gor y in t he  gr a ss (6or 7)t o olbox of the pr ocessing m od u le .  This sh o uld  p rovidea listof ra s ter val ues. Copy  these va lu es.Y o u c an use r.q uantilefor conti n uousd at a.

 col_% 10_== 0: progress.setPercentage(int(100*col/xsize))
 _ __ __for row in_range( ysize ):
_   _  __   cell_value = raster[row, col]
       __ __#_check if cell_value is NaN_- don't add if it_is
 _       __ if not_math.isnan(cell_value):
        _     _ # round_floats_if_needed
   _     _     _if rdig:
     _     _    _ _ try:
   _  _ _  _     _  _   cell_value = round(cell_value,_int(rdig))
_  ___ _  __ __     except:
__      _   __   _    _ cell_value = round(cell_value)
  _ _ _         # Add_to the unique values set
 _   _ __  __ _ cell_values.add(cell_value)

del(gdalData)

# decide whether to sort by_the count-column_or the value-column
sort_values = sorted(cell_values)

# Now_load the layer and_apply_styling
layer = processing.getObjectFromUri(input)

qCRS = QgsColorRampShader()

# Build_the colour ramp using random colours
colList_= ['#ff0000','#ffff00','#0000ff','#00ffff','#00ff00','#ff00ff']

lst = []
for i,val_in_enumerate(sort_values):
_   lst.append(QgsColorRampShader.ColorRampItem(val,QColor(colList[i %_6]),str(val)))

qCRS.setColorRampItemList(lst)
qCRS.setColorRampType(QgsColorRampShader.EXACT)

shader = QgsRasterShader()
shader.setRasterShaderFunction(qCRS)

renderer = QgsSingleBandPseudoColorRenderer(layer.dataProvider(), layer.type(),_shader)
layer.setRenderer(renderer)
layer.triggerRepaint()

A:

You could try_this:
1) Create a simple style in Layer_properties,_then save it to an export_file_using the save button.  These_are_in_the form:
value, R, G, B,_Alpha, label
2) Use r.category in the_grass (6 or 7) toolbox of the processing module._ This should_provide a list of raster_values._Copy_these values. You can use r.quantile for continuous data.
