I am trying to populate 3 fields in a feature class with the symbology colour in RGB.
My conversion code takes the H, S and V values given by the layer.symbology.renderer.symbol.color function.
A sample of the output from the color function is: {'HSV': [61, 50, 55, 100]}
The values must be munged to cater for the ArcGIS colour model ;
My code is:
def colourHSVtoRGB(self,H,S,V):
# The ArcGIS HSV model is strange - Hue 0-240, Saturation 0 - 255, Value 0 - 255
from matplotlib.colors import hsv_to_rgb
# Convert hval to 360 and make it 0 - 1
hval = 3.6 * (H / 240)
sval = S / 255
vval = V / 255
invals = [hval, sval, vval]
rg = hsv_to_rgb(invals)
R = rg[0]
G = rg[1]
B = rg[2]
# Convert to 0 - 255
R = int(round((R * 255), 0))
G = int(round((G * 255), 0))
B = int(round((B * 255), 0))
Unfortunately this gives the incorrect RGB values.
From a colour web site, the RGB for HSV = 61, 50, 55 should be 139, 140, 70, which also looks like the correct colour.
My function outputs RGB values; 49, 55, 44 - clearly wrong.
The input values to the matplotlib function are all 0 - 1. I'm sure my interpretation of the calculation for this input could use some improvement.
Thanks,
J