4

I'm trying to understand whether it is possible to corectly display colours in British Geological Survey maps. Our client has a licence to use the shapefiles but unfortunately BGS don't provide SDL files. In theory, the information to correctly colour each formation is available in the shapefile attribute table so I'm wondering whether some python coding would do the trick.

There is a field that assigns the formation (LEX_RCS) type to each polygon so this is the field you read to colour the polygon. Then there is a field (BGSREF) that assigns the colour to that field. The BGSREF field is a 3 digit field (YCM - Yellow Cyan Magenta). Each digit is from 0 to 9 assigning a percentage of that colour (i.e. 0 is 7%, 1 is 14 % ... 9 is 100%). Therefore, by reading the BGSREF field, you can then assign the colour to the LEX_RCS field for that polygon.

From what I can see, the symbology properties do not allow for this in QGIS 2.0 so I'm wondering whether some python coding would do it.

Regards Antonio

8

It might well be possible with QGIS 2.0 to do this. In the Style->Symbol Selector you can choose Data defined properties There you can assign the color based on an expression which also can calculate based on different schemes, CMYK among others. You would have to transform your values to a format accepted as input there.

CMYK as input for data defined properties Source: https://gis.stackexchange.com/a/60467/9839 (Thanks @NathanW)

  • 1
    +1. This should be straight forward enough as the input for color_cmyk(cyan, magenta, yellow, black) is a percentage. So, it should be a simple process of parsing the 3 digit field and casting each digit as its equivalent % value in color_cmyk() expression taking care to note the QGIS is expecting CMYK in that order and the OP has YCM (K being black and therefore always zero in this case). – MappaGnosis Sep 30 '13 at 17:05
  • Ok, cheers. This stuff rocks! Here the code that I used to get the colours – geotux Sep 30 '13 at 20:54
1

Ok, cheers. This stuff rocks! Here the code that I used to get the colours

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

The problem is that the colours are now showing correctly in the map but can't get the legend to show all these colours. Any clues? Basically it's showing all in black. I'm using the "single symbol". I tried the "categorised" and added the above code for the colouring but as soon as I click the "Classify" button after choosing the "LEX_RCS" attribute (remeber the colours are reading the BGSREF attribute) everythng goes black in the symbology window but the colours display correctly on the map. Suggestions^

Cheers

  • The legend issue has been discussed here: gis.stackexchange.com/questions/63713/… – underdark Sep 30 '13 at 21:14
  • Ok, I suppose that answers the question. Clearly its a severe limitation given that BGS just won't provide the SDL version of the ESRI layer file .... – geotux Oct 1 '13 at 8:25
0

You can now use CMY colors in QGIS 2.0, see the Nathan W response in Data-defined Styles in QGIS

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.