Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a large geology data set that I need to display using an industry standard set of symbols and colours. The symbols and colours are attributes of the data. I have been using the data defined symbols capability of the dev build of QGIS (code revision b805894) to display the data according to its attributes. This works perfectly in terms of displaying the data correctly in the map window.

The problem arises when I try to create a legend in the composer. The data-defined colours displayed on the map don't pull through to the legend.

Here are some screens shots. The first shows the map window. You can see the problem manifesting in the Layers box on the left. The symbols are all coloured black.

The second screen shot shows the composer window with a legend.

enter image description here

enter image description here

share|improve this question
just upload your screens to imgur or similar and post the link. Edit your post to add the pictures. Furthermore: Which QGIS-Version are you using (as the composer has gone through many changes in the current QGIS master)? – Curlew Jun 17 '13 at 16:15

I think legends for data-defined symbology are not implemented yet. I've opened a bug report/feature request:

Thinking about it, data-defined symbology is extremely powerful and might result in hundreds of different variations of a symbol in color, shape, size, rotation, and so on. It might be unfeasible to really have a legend in such a case.

share|improve this answer
Thanks for the reply, and for opening the feature request. Data defined symbology is a fantastic tool, however in my mind it would be severely limited if it was unable to be used in the production of professional maps. – Kris Jun 21 '13 at 8:08

I'm not sure it can be of any use for complex cases, but I manage to get a fake legend by adding a shape layer.

I then created points in the new layer with the same kind of data than used to defined the symbology, and located where I wanted the legend to appear. Then I defined the same symbology for this layer, and showed the corresponding data values as labels.

share|improve this answer
This "trick" works especially well for graduated circles (or similar) legends! – Andrew Tice Oct 22 '13 at 3:53

I am having the same problem with geological maps in QGIS 2.10. The maps supplied have a have a CMYK colorcode (Actually "YMCK" )that can be interpreted with the following formula:

CASE WHEN substr("COLOR_CODE",3,1 ) IS 0 THEN 0
  WHEN substr("COLOR_CODE",3,1 ) IS 1 THEN 7
  WHEN substr("COLOR_CODE",3,1 ) IS 2 THEN 14
  WHEN substr("COLOR_CODE",3,1 ) IS 3 THEN 21
  WHEN substr("COLOR_CODE",3,1 ) IS 4 THEN 31
  WHEN substr("COLOR_CODE",3,1 ) IS 5 THEN 42
  WHEN substr("COLOR_CODE",3,1 ) IS 6 THEN 54
  WHEN substr("COLOR_CODE",3,1 ) IS 7 THEN 67
  WHEN substr("COLOR_CODE",3,1 ) IS 8 THEN 80
 ELSE 100
CASE WHEN substr("COLOR_CODE",2,1 ) IS 0 THEN 0
  WHEN substr("COLOR_CODE",2,1 ) IS 1 THEN 7
  WHEN substr("COLOR_CODE",2,1 ) IS 2 THEN 14
  WHEN substr("COLOR_CODE",2,1 ) IS 3 THEN 21
  WHEN substr("COLOR_CODE",2,1 ) IS 4 THEN 31
  WHEN substr("COLOR_CODE",2,1 ) IS 5 THEN 42
  WHEN substr("COLOR_CODE",2,1 ) IS 6 THEN 54
  WHEN substr("COLOR_CODE",2,1 ) IS 7 THEN 67
  WHEN substr("COLOR_CODE",2,1 ) IS 8 THEN 80
  ELSE 100
CASE WHEN substr("COLOR_CODE",1,1 ) IS 0 THEN 0
  WHEN substr("COLOR_CODE",1,1 ) IS 1 THEN 7
  WHEN substr("COLOR_CODE",1,1 ) IS 2 THEN 14
  WHEN substr("COLOR_CODE",1,1 ) IS 3 THEN 21
  WHEN substr("COLOR_CODE",1,1 ) IS 4 THEN 31
  WHEN substr("COLOR_CODE",1,1 ) IS 5 THEN 42
  WHEN substr("COLOR_CODE",1,1 ) IS 6 THEN 54
  WHEN substr("COLOR_CODE",1,1 ) IS 7 THEN 67
  WHEN substr("COLOR_CODE",1,1 ) IS 8 THEN 80
  ELSE 100
CASE WHEN substr("COLOR_CODE",4,1 ) IS 0 THEN 0
  WHEN substr("COLOR_CODE",4,1 ) IS 1 THEN 7
  WHEN substr("COLOR_CODE",4,1 ) IS 2 THEN 14
  WHEN substr("COLOR_CODE",4,1 ) IS 3 THEN 21
  WHEN substr("COLOR_CODE",4,1 ) IS 4 THEN 31
  WHEN substr("COLOR_CODE",4,1 ) IS 5 THEN 42
  WHEN substr("COLOR_CODE",4,1 ) IS 6 THEN 54
  WHEN substr("COLOR_CODE",4,1 ) IS 7 THEN 67
  WHEN substr("COLOR_CODE",4,1 ) IS 8 THEN 80
  ELSE 0

but this gives the black color in the legend boxes.

So I thought I could solve the problem by using the above script to compute a new color field which worked quite well and returned the RGB values such as 255,200,220. Then I tried


to produce a data defined color without any luck (invalid formula) ! So I parsed the color field into 3 fields - Red, Green and Blue and the following formula -


in the data defined color formula box gave the right color on the map and the legend is no longer black - but uses the color ramp settings to determine the legend color.

It seems we need an option on the color ramp drop down box to specify data defined colors and then it should use whatever the data defined color is to produce the legend.

All other work-arounds are fine but when using the legend filter on the map composer one wants to get the right result and not have to go to every legend box and type in the rgb codes in the choose color options.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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