2

So let's say I have an integer id column that users regularly add features to. mytable1 has 500 features and growing.

When doing a categorized view on these, I'll get 500 different colors for all these features. Now problem is that when a new feature gets created, it does not get styled in any way. I can introduce a new style with an else but then every new feature will be the same color

Now is there a way that every feature with an id ending in 0 to be red (essentially, id 0, id 10, id 110,...) and every feature with id ending in 1 to be blue (id 1, 11, 31, 61,...).

Bonus if I was allowed to actually have 30 colors instead of just 10.

So ids 1, 31, 91, 301 will have same color

And ids of 29, 59 , 89 will have same color

Is there a way of doing this in QGIS?

2

You could use the data defined properties for the color. you just have to create a fonction to attribute right color to the right feature. The problem with this way is that you cant get a legend (or you have to manually create the legend)

One way to set the color could be to use this (maybe not the most efficient way...):

CASE
    WHEN "OBJECTID" % 10 = 0 THEN '255,0,0,255'
    WHEN "OBJECTID" % 10 = 1 THEN '0,255,0,255'
    WHEN "OBJECTID" % 10 = 2 THEN '0,0,255,255'
    ...
    ELSE '125,125,125,255'
END

You just need to set the "= x" part to the last digit you need and adjust the [r,v,b,a] value to your liking

  • Ideally I'd like to stay away from creating more functions or columns as the data is already quite big. How about creating 30 rules with different colors and each rule would be "OBJECTID" % 10 = 0 "OBJECTID" % 10 = 1 "OBJECTID" % 10 = 2 do you think this would work? – Luffydude Jan 3 at 10:41
  • Yes it will also work with rule based styling, but with this formula you will get only 10 rule (from "OBJECTID" % 10 = 0 to "OBJECTID" % 10 = 9 as the formula return the value of the last digit), if you want 30 color you will need to be more creative with the rule – J.R Jan 3 at 10:58
  • would for example "OBJECTID" % 20 = 10 work? – Luffydude Jan 3 at 11:37
  • 1
    No the '%' is the modulo operator, it give you the remainder of division; using 'x %10' give you the last digit of x but that's a spacial case of dividing by ten – J.R Jan 3 at 12:11
  • Well alright I guesss I'll just stick to 10 then, thanks! – Luffydude Jan 3 at 17:00

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.