4

I'm trying to figure out a way to get a consistent color scheme across layers of different types.

I have a layer of lines (electrical cables) and a layer of points (electrical nodes). The elements in those layers have an integer attribute that corresponds to the ID of their electrical power source.

Simply put, I'd like the cables and node that share the same power source to have the same (random) color.

So I made a categorized style with random colors on one of the layer but I cannot copy it to the other layer since I cannot copy a style from a layer of points to a layer of lines. And if I make another categorized style on the other layer, the random colors will be different.

Also, I can not copy each color by hand since I have about 200 different possible values of the attribute.

Is there a reasonably simple way to achieve what I want to do ?

1

Defining colours by attribute in single symbol symbolisation is possible. It wants an attribute like this:

Data defined override  
Active: no   (ctrl|right-click toggles)  
Expected input:  
string [r,g,b,a] as int 0-255
Valid input types:  
string  
Current definition :  
undefined 

I haven't tested this BUT you could try something along the lines of:

  • Create a table in excel or similar with a complete list of the electrical ID numbers
  • Use formulae to randomly generate values for rgba (quite easy in excel)
  • Load the table into QGIS and join it to the layers that you want to symbolise, based on the power source ID
  • Symbolise the layers as single symbol but define colours by the attribute in the table
  • Hello, I've thought about this but then I loose the benefit of having a legend with single symbol style. And if I use this in the categorize style, the legend won't take the color defined by the attribute. – Tilim Nov 3 '16 at 16:46
  • True. Looking at the Categorise dialogue if you go into Advanced there is an option to Match to Symbols from File. It appears to want an xml file but I can't find any details on it at all; might be possible to hack some xml files that would do both lines and points? – Ed Rollason Nov 3 '16 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.