I have a layer where each feature represents a route, and I want these routes to be automatically categorized based on their unique IDs. In other words, if I have two routes, I should have two categories, and when I add a third route, it should automatically be assigned its own category.
Furthermore, when a route is deleted, its corresponding category should also be removed. Essentially, the number of categories should always correspond to the number of routes/features in the layer. I have managed to categorize these features manually, but this doesn't update automatically when I add or remove features.
I understand that this might involve some sort of scripting, possibly with PyQGIS. How can I achieve this?