How to assign RGB colours to QGIS vector file

A frequent request of MRT is whether we have a symbology file for the geology polygon layers that can be imported into QGIS to replicate the map images. It so happens that an RGB text file has been made available that has the correct colours. Unfortunately patterns are not available but in a subsequent blog I will outline how to create them in QGIS

There are two ways to do this:
A) The simple way (but does not create a useful legend)


1.       Join a RGB table of values to the matching geology layer based on a common field.
The table can be something like this (space delimited example):
 Code R G B
9502 24 38 240
9500 32 62 10
etc

2.       In the Symbology window for the geology layer choose single symbol option (at the top of the screen). Not exactly  intuitive!




3.       Press the data defined override expression button to the right of the Fill Colour option (this turns yellow when it is being used) and choose Edit in the dialogue box to get you to the expression string builder.


4.       Type in the following expression  color_rgb("R","G","B") (see screenshot below). OK your way out of this and Apply. This should provide the basic colours without any patterns.




Figure 1 Example using the MRT 25k geology layer

The example map honours the colours published by MRT. Note that each printer may produce slightly different colours from a MRT paper map, but it will be close enough.

B) The slightly more complicated way that gives you a legend.

1) This time choose the Categorised option in the Symbology properties of the geology vector file.
Insert the color_rgb("R","G","B") expression in the Value box. (Note that the RGB letters have to reflect the field names in your attribute table!)

You can see that our legend will contain the RGB values. Here is a work around to fix this!
2) Open the Legend properties (Screen grab below). Enable the Text on Symbols option at the top. This will place a text on the colour box.
3) Use the Set Labels from Expression option to assign the field you wish to use for the text as below. In this case I have used the Text Format option to place a buffer around the text.


4) Go to the Print Layout to view your map and its linked legend. By playing with the Legend properties you can expand the box size so that the text for each unit sits within the box. Finally you can set the colour of the text to the right of the colour boxs to white so they are no longer visible on the Layout.


Now, why dont the colours match between the legend and the map? Is this a bug? More work to do to solve this. Any suggestions?


Comments

Popular posts from this blog

Orthorectification of historic aerial photos

Geological Dip and Strike Label Placement in QGIS