1

I've the 8 social classes (see under) for +- 900 polygons. I would like to create a new column that keep only name of the main social class for each row (based on the percentage). After that I would like to set a color for each polygon based on the major social class in it.

|   | bureau | CS1                  | CS2              | CS3              | CS4              | CS5              | CS6              | CS7              | CS8              |
|---|--------|----------------------|------------------|------------------|------------------|------------------|------------------|------------------|------------------|
| 1 | 101    | 0.000543797261927398 | 6.39760099954826 | 35.3448745188225 | 12.4775915818504 | 7.0610910561502  | 2.78350275427263 | 17.5344485748163 | 18.4706452869407 |
| 2 | 102    | 0.0833792083846865   | 4.71178099155645 | 38.947249168602  | 12.664389902742  | 11.382192650638  | 2.39111672203692 | 16.1342822915544 | 13.6751866634374 |
| 3 | 103    | 0.177533456592499    | 4.44507934549473 | 39.2964921235435 | 15.4694031513017 | 11.2500227953552 | 2.60237087604638 | 13.7660576214535 | 13.0155179780742 |
| 4 | 104    | 0.15873318630476     | 3.98029853494405 | 37.1732526731557 | 15.6841983264699 | 12.9923578110956 | 3.4037063750489  | 13.2499374112967 | 13.3569488994092 |
| 5 | 105    | 0.100023025825703    | 3.80769682422482 | 34.0805398317955 | 15.3453144362231 | 15.6672496204983 | 3.67494171412793 | 13.9390141521583 | 13.4010089709952 |

I think I need to use the field calculator but I didn't use it for a long time so I'm stuck with the realization !

2

This expression: max(CS1,CS2,CS3,CS4,CS5,CS6,CS7,CS8) will return highest CS value. Put that expression into a new field, let's call it max_CS. Make sure the new field has as many decimal places as your CS fields (if the CS fields have different numbers of decimal places, use the highest number).

This expression uses nested if() functions to find the name of the CS field that has the value that matches the value in max_CS:

if(max_CS=CS1,'CS1',if(max_CS=CS2,'CS2',if(max_CS=CS3,'CS3',if(max_CS=CS4,'CS4',if(max_CS=CS5,'CS5',if(max_CS=CS6,'CS6',if(max_CS=CS7,'CS7',if(max_CS=CS8,'CS8','no match'))))))))

It's not a very elegant method, but it gets the job done. Use this function to create the field you actually wanted. Use the new field as the category for categorized rendering style.

  • 1
    Thanks it worked ! And for the others that would need this : to have a match, you need to set your new field with the same significant figures than the others ! – Svhooren May 4 at 18:24
  • 1
    Good tip. I'll add that to my answer, since comments sometimes get deleted. – csk May 4 at 20:43

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.