1

I want to write a text/xml file that will serve in QGIS 3.26 as a discrete colormap of a vector layer by one of its fields (using Symbiology->Categorized):

The field mentioned has 100 values but I want to specifically assign unique colors only to 3 values ,the other 97 values should be mapped to a single color as follows:

  1. 'Spain' should be mapped to RGB value (120,34,25)
  2. 'Italy' should be mapped to RGB value (12,238,45)
  3. 'Romania' should be mapped to RGB value (127,100,200)
  4. All other values should be mapped to RGB value (0,0,0)

How do I achieve this?

2
  • 3
    Must it be using a using a separate file, or would simply using a rule-based symbology be sufficient?
    – Matt
    Commented May 29, 2023 at 18:29
  • @Matt - no, I will look into that. it looks suffice
    – user172775
    Commented May 30, 2023 at 8:01

1 Answer 1

1

In the layer styling panel, for Fill color, use data driven override > Edit and insert this expression (see below for color values from a separate table):

case 
when NAME = 'Spain' then '120,34,25'
when NAME = 'Italy' then '12,238,45'
when NAME = 'Romania' then '127,100,200'
else '0,0,0'
end

enter image description here


If you already have a separate table with the color values, make a table join to add the color information attribute field to your vector layer. Then simply use the name of the joined field as the expression and set fill color (for all other countries) to black.

Table join enter image description here

Setting the attribute fieldname in data driven override for Fill color: enter image description here

Your Answer

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

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