Ejemplo n.º 1
0
def createRasterShader(fields, mode = "rgb", scale = "float"):
    shader = QgsRasterShader()
    colRamp = QgsColorRampShader()
    colRamp.setColorRampType(QgsColorRampShader.INTERPOLATED)
    
    ramp = []
    col = QColor()
    
    for line in fields:
        val = float(line[0])
        txt = unicode(line[1])
       
        if mode == "rgb" or mode == "rnd":
            if scale != "float":
                color = [float(x)/255.0 for x in line[2:6]]
            col.setRgbF(*color)
            
        elif mode == "hsv":
            if scale != "float":
                color = [float(x)/float(y) for x,y in zip(line[2:6], [360, 100, 100, 255])]
            col.setHsvF(*color)
            
        elif mode == "hex":
            col.setNamedColor(str(line[2]))

        ramp.append(QgsColorRampShader.ColorRampItem(val, col, txt))
    
    colRamp.setColorRampItemList(ramp)
    shader.setRasterShaderFunction(colRamp)
    
    return(shader)
Ejemplo n.º 2
0
	def __init__( self, parent ):
		super( HueSliderWidget, self ).__init__( parent )
		self.setFixedSize( parent.width(), parent.height() )
		self.value = 0
		size = 100
		self.colorImage = QtGui.QImage( 1, size, QtGui.QImage.Format_RGB32 )
		c = QColor()
		for y in range( 0, size ):
			k = y/float(size)
			c.setHsvF( k, 1.0, 1.0 )
			self.colorImage.setPixel( 0, y, c.rgb() )
		self.setCursor( Qt.PointingHandCursor )
Ejemplo n.º 3
0
	def __init__( self, parent ):
		super( AlphaSliderWidget, self ).__init__( parent )
		self.setFixedSize( parent.width(), parent.height() )
		self.setCursor( Qt.PointingHandCursor )
		self.value = 0
		size = 100
		self.colorImage = QtGui.QImage( size, 1, QtGui.QImage.Format_RGB32 )
		c = QColor()
		for x in range( 0, size ):
			k = x/float(size)
			c.setHsvF( 1.0, 0.0, k )
			self.colorImage.setPixel( x, 0, c.rgb() )
Ejemplo n.º 4
0
def generateHSVImage( w, h, hue, img = None ):
	if not img:
		img = QtGui.QImage( w, h, QtGui.QImage.Format_RGB32 )
	du = 1.0/w
	dv = 1.0/h
	c = QColor()
	for y in range( 0, h ):
		for x in range( 0, w ):
			s = du * x
			v = 1.0 - dv * y
			c.setHsvF( hue, s, v )
			img.setPixel( x, y, c.rgb() )
	return img
Ejemplo n.º 5
0
def get_popularity_color(hpop, alpha=1.0):
    """Get a color that represents some darkish cool looking color interpolated between 0 and 1.

    :param float hpop: the value (between 0 and 1) of the color.
    :param float alpha: The alpha value of the color (between 0 and 1).
    :returns: a :class:`QColor <PyQt4.QtGui.QColor>` object to put into a :class:`QWidget <PyQt4.QtGui.QWidget>`, or converted into a hex color.
    :rtype: :class:`QColor <PyQt4.QtGui.QColor>`

    """
    assert (hpop >= 0)
    h = hpop * (0.81 - 0.45) + 0.45
    s = 0.85
    v = 0.31
    color = QColor('white')
    color.setHsvF(h, s, v, alpha)
    return color
Ejemplo n.º 6
0
 def addMarker(self, selection):
     rows = [m.row() for m in selection.indexes()]
     if not rows:
         return
     max_row = max(rows)
     if max_row < len(self.markers) - 1:
         self.beginInsertRows(self.root, max_row + 1, max_row + 1)
         new_pt = (self.markers[max_row] + self.markers[max_row + 1]) / 2
         col1 = self.colors[max_row]
         col2 = self.colors[max_row + 1]
         col = QColor()
         if self.mode == "rgb":
             r = (col1.redF() + col2.redF()) / 2
             g = (col1.greenF() + col2.greenF()) / 2
             b = (col1.blueF() + col2.blueF()) / 2
             a = (col1.alphaF() + col2.alphaF()) / 2
             col.setRgbF(r, g, b, a)
         elif self.mode == "hsv":
             h = (col1.hueF() + col2.hueF()) / 2
             s = (col1.saturationF() + col2.saturationF()) / 2
             v = (col1.valueF() + col2.valueF()) / 2
             a = (col1.alphaF() + col2.alphaF()) / 2
             col.setHsvF(h, s, v, a)
         else:  # cyclic_hsv
             h1 = col1.hueF()
             h2 = col2.hueF()
             if h2 < h1:
                 h1, h2 = h2, h1
             if h2 - h1 < 0.5:
                 h = (h2 + h1) / 2
             else:
                 h = (h1 + h2 + 1) / 2
                 if h > 1:
                     h -= 1
             s = (col1.saturationF() + col2.saturationF()) / 2
             v = (col1.valueF() + col2.valueF()) / 2
             a = (col1.alphaF() + col2.alphaF()) / 2
             col.setHsvF(h, s, v, a)
         self.markers.insert(max_row + 1, new_pt)
         self.colors.insert(max_row + 1, col)
         self.endInsertRows()
Ejemplo n.º 7
0
 def addMarker(self, selection):
     rows = [m.row() for m in selection.indexes()]
     if not rows:
         return
     max_row = max(rows)
     if max_row < len(self.markers)-1:
         self.beginInsertRows(self.root, max_row+1, max_row+1)
         new_pt = (self.markers[max_row] + self.markers[max_row+1])/2
         col1 = self.colors[max_row]
         col2 = self.colors[max_row+1]
         col = QColor()
         if self.mode == "rgb":
             r = (col1.redF()+col2.redF())/2
             g = (col1.greenF()+col2.greenF())/2
             b = (col1.blueF()+col2.blueF())/2
             a = (col1.alphaF()+col2.alphaF())/2
             col.setRgbF(r,g,b,a)
         elif self.mode == "hsv":
             h = (col1.hueF()+col2.hueF())/2
             s = (col1.saturationF()+col2.saturationF())/2
             v = (col1.valueF()+col2.valueF())/2
             a = (col1.alphaF()+col2.alphaF())/2
             col.setHsvF(h,s,v,a)
         else: # cyclic_hsv
             h1 = col1.hueF()
             h2 = col2.hueF()
             if h2 < h1:
                 h1,h2 = h2,h1
             if h2-h1 < 0.5:
                 h = (h2+h1)/2
             else:
                 h = (h1+h2+1)/2
                 if h > 1:
                     h -= 1
             s = (col1.saturationF()+col2.saturationF())/2
             v = (col1.valueF()+col2.valueF())/2
             a = (col1.alphaF()+col2.alphaF())/2
             col.setHsvF(h,s,v,a)
         self.markers.insert(max_row+1, new_pt)
         self.colors.insert(max_row+1, col)
         self.endInsertRows()