I am creating a map of survey held by my employer. I am trying to use a simple 'traffic-light' symbology pattern to quickly see the survey age. So survey that is ten years or older will be red, 8-10 years amber and less than 8 will be green. The data contains a field called YEAR, contain the year as a number.
I'm attempting to symbolise using an expression but I'm a little overwhelmed by all the date options that appear. So far for my red symbol I have tried the following:
Solved! Go to Solution.
You need an expression that determines all three of your symbols at once.
When(Year(Today())-$feature.year >= 10, '10+', Year(Today())-$feature.year >= 8, '8-10', '<8')
This expression subtracts the feature year from the current year, and if the difference is greater than or equal to 10 then it goes into the 10+ bucket. If it is not, it keeps checking and looks to see if the difference is greater than or equal to 8. If it is, it goes in the 8-10 bucket. If not, it goes into the default bucket of <8.
Note that I am using $feature.year, but that might be slightly different for you based on your Year field name. The easiest way to determine what that value should be, is to use the variable picker to add it to your expression for you.
In the style panel, you can then assign your desired symbology to those buckets.
Does this work for you:
if ($feature.year > (Year(Now()) + 10));
This uses the Year() function with the Now() function to get the current year:
Hmmm no it still seems to capture all the features; I also had to remove the 'if'.
You need an expression that determines all three of your symbols at once.
When(Year(Today())-$feature.year >= 10, '10+', Year(Today())-$feature.year >= 8, '8-10', '<8')
This expression subtracts the feature year from the current year, and if the difference is greater than or equal to 10 then it goes into the 10+ bucket. If it is not, it keeps checking and looks to see if the difference is greater than or equal to 8. If it is, it goes in the 8-10 bucket. If not, it goes into the default bucket of <8.
Note that I am using $feature.year, but that might be slightly different for you based on your Year field name. The easiest way to determine what that value should be, is to use the variable picker to add it to your expression for you.
In the style panel, you can then assign your desired symbology to those buckets.
This worked perfectly, thank you!