I'm representing an archaeological site in QGIS and I have expressed the multiple contexts (stratigraphic units) as polygons with categorized symbology so that the client can toggle off and on the contexts they want to see etc.

My issue is that, oftentimes, these contexts overlap or cut into other contexts due to historic construction phases and deposition/accumulation. So, I've added an attribute called 'phases' and I want to include that alongside my 'context' symbology so that if you toggle off one phase, all the contexts within that phase disappear while the phase that is visible, the individual contexts can be toggled on and off.

Is there a way for this to be done?

  • I think it makes sense, but I woild need a bit more explanation to be sure. You are using non-overlapping polygons, so you have e.g. three neighboring polugons ore representing a context from phase A, the next one from phase A and B and the third one from phase B? Can you uplod a screenshot of your data set? – MortenSickel Mar 5 at 6:43

Yes, your request is easily solvable using the Rule-based symbology.

In the stratigraphic unit/context polygon layer symbology, select the option Rule-based: here you can create different rules, one for each phase of your site using as a filter the expression

"Phase" LIKE "A"  

picturing that your Attribute field with the phases information is called Phase and that the phases are A, B, C, etc..

When all your phases are ready, you can create a sub-category inside each of them, categorising the style according to the context number and filtering them with the phase info.

To do it, right-click in the rule label and in the menú and select Refine Current Rule > Add Categories to Rule

enter image description here

This will open a new window for categorising the symbology: here select the expression symbol in the right of Column and use the expression

IF ("Phase" like 'A', "Context", NULL)

Obviously , "Phase" is your Phase field and "Context" your Context field. Change the A, B, C, according to your phase name.

This will create a selection of contexts that have that phase as attribute. All the others will be ignored. Press Classify and you will have your selection. I suggests to remove now the Null option (the green in the image).

enter image description here.

Repeat the operation for all the phases.

Two necessary steps to have a good result are: 1. Make not visible the Phase symbol to allow the underlying symbols to be visible: to do this right-click in the Phase rule Label and select Change opacity from the menú > opacity to O. 2. The system, as you will realise, create a label for the context using the expression and his result. Double-click in the label name and change it from the default to the context number.

This will be your final result: enter image description here

Hope that this suit your request. As a geomatics archaeologist, I can say to you "Have fun!"

| improve this answer | |

If I understand you correctly and each polygon is representing one or more contexts, I think the way of doing it is to make a field for coding multiple contexts, e.g. as a comma separated string. Then you make a copy of the layer for each context, each filtered on your coding field. Then each of the copies can be toggeled on or off to show a given context or set of contexts.

There are two difficulties in this: One is aboit displaying. If you want all your context potentially to be visible at once, you need to use hashing as symbology. It needs to be selected carefully if you want to be able to show more than two or three overlappkng at once.

The other problem is in the coding. The simplest way of doing it woild be just to list the contexts and look for a given name in the filter (I do not have QGIS available now, so I cannot give the details how to do it). The problem here is if you have overlapping context names. I.e. if you have one called 'old' and another 'very old', if you look for 'old' both would match. There are (at least) three ways of getting around this.

If you know your set of contexts and you have or can make sure you have no overlapping names, you are fine.

If you have overlapping names, in the labeling field and in the filter, add on a special character at the start and the end. E.g :old: and :very old:, also use those characters in the filter.

If you can use python, write an expresdion where you split the field into an array, search for your context name as an element in the array.

Hope this helps.

| improve this answer | |

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.