8

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

1
  • 2
    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, 2013 at 16:15

6 Answers 6

10

Legends for data-defined symbology are not implemented yet. There is an open bug report/feature request: https://issues.qgis.org/issues/11491

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.


Update 2017-08:

QGIS3 will include an automatic legend for data-defined size:

enter image description here

4
  • 2
    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.
    – ManChild
    Jun 21, 2013 at 8:08
  • RE:Update 2017-08: What about for data-defined colors? As is the case in the OP...
    – Chris
    Nov 17, 2017 at 0:14
  • @Chris not implemented as far as I know
    – underdark
    Nov 19, 2017 at 19:57
  • We now have QGIS 3.0; is the automatic legend for data-defined size now available?
    – Cezar B
    Apr 13, 2018 at 9:05
5

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.

1
  • This "trick" works especially well for graduated circles (or similar) legends! Oct 22, 2013 at 3:53
4

I had to create a legend for a categorized symbology based on data defined color. QGIS 3 did not solve it for me. So I created a attribute containing the catagory value concatenate to the color hexa code.

I created a random categorized style for this column, exported this style to sld file and then manipulate it with regexp into a text editor to replace for each rule the filling color code by the code mentionned in the category name. After that I cleaned the cataegory value and the name of the filtered column and I finally apllied that new style to my layer.

Sorry the link above is in french.

http://si.cenlr.org/24-11-2017

3

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:

color_cmyk( 
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
END,
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
END,
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
END, 
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
END)

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

Color_rgb("Color") 

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 -

color_rgb("Red","Green","Blue")  

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.

3

I have had discussions with the geological survey here in Western Australia and they can supply data files with geological codes, rgb colours and geological pattern codes. We just need a plug-in to read in these files to add these attributes to the polygons so thay can be displayed in the legend. I have tried the color(rgb) option but the legend creator does not see these colours.

0

I had the same problem ... rgb(red, green, blue) where red, green, blue are values listed in the attribute table can be used to set the map color, but then the color is not replicated in the layers panel and then not transferred to a legend in print composer ... what I had to do was click on each of the layers in the layers panel and then pick and reset colors in the layers panel from the map ... a tedious solution ... there should be a way to code this in PyGIS ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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