[GIS] Changing marker shape based on a rule or column value in QGIS

qgisstylesymbologyvisualisation

I am using QGIS 2.14.14. I am styling point markers in a layer that I imported using "Add Delimited Text Layer". I want to style the markers based on three properties:

  1. Color of marker relates to study name
  2. Size of marker relates to number of soil samples at that location

(I have successfully completed the first two requirements, especially with the help of this post:
How to style points in QGIS based on multiple attributes).

I used a categorized style and made a color gradient to create the different colors for the studies, and I used the "size assistant" to change the size of the marker.

3. Shape of marker denotes if the soil samples were taken in "topsoil" or "other".

Specifically, I would like the shape to be a square if it's taken from "topsoil" and a circle if it's taken from "other".

I can not find a way to change the shape based on a condition or a certain value in my attributes table. I have tried making a column that's a whole number field and binary (1 for topsoil, 2 for other). I have also tried making a text field ("Topsoil" for topsoil and "Other" for other).

Does anyone know of a way to successfully combine these three formatting conditions? Specifically, does anyone know how to conditionally format a marker shape based on some attribute?

Best Answer

Assuming to start from a point layer having this Attribute Table:

enter image description here

you can perform the third step:

"Shape of marker denotes if the soil samples were taken in "topsoil" or "other"."

by firstly going to Properties >> Style and then applying these settings:

enter image description here

Once you have done this, click Edit... from the button near the several symbols:

enter image description here

and type this expression:

CASE
WHEN
"origin" = 'topsoil' THEN 'square'
WHEN
"origin" = 'other' THEN 'circle'
END

Finally, click the Apply button for applying the changes and you will get something like this (you may then adapt sizes and colors as you want):

enter image description here