TransWikia.com

QGIS 3: Categorised symbology with value driven alpha transparency

Geographic Information Systems Asked on May 26, 2021

I’m looking for a bit of guidance on how to use categorised symbology with QGIS, and data driven alpha. Ie, I want to be able to specify a colour ramp on one columns values, and the transparency of the polygon based on another columns values.

I’ve found this post which somewhat describes how it might be possible by using the following code snippet, and assumes there is a column named "transparency" whose value is between 0 and 1.

set_color_part(@value, 'alpha', ( 1 - "transparency" ) * 255 )

Now, the question I have, is I have a column called MyClassification by which I want to categorize. There’s perhaps 300 unique values, so I don’t wish to do this by hand. Rather, I’d like to set a color ramp, indicate that column, hit classify, and have QGIS put in the colours. What I can’t seem to work out is how I can use that expression in the expression builder to use transparency from the transparency column, and still use MyClassification with a classified colour ramp.

Any ideas?

One Answer

I'm going to answer this one.

Open the symbology pane. Use categorise and set a ramp. Classify. Select all classifications, click the down arrow next to symbols up the top. Select Configure Symbol. Click the word "simple fill" in the top panel. Click the menu next to fill_colour, about 3/4 the way down the menu click edit.

Make it look like the following, with a simple line and simple fill. You can do this with all categories by selecting all categories, then adding a simple line and clicking apply/ok to close the dialogue. enter image description here

Then, you want the lines colour to always match the simple fill. Do this by using the following code snippet in the place indicated by the following picture.

color_rgba(color_part(@symbol_color, 'red'),color_part(@symbol_color, 'green'),color_part(@symbol_color, 'blue'),color_part(@symbol_color, 'alpha'))

enter image description here

enter image description here

Then, when you wish to modify colours / transparency, you do it through the main window, per the below, with the "Fill" symbol selected.

enter image description here

There is a bug where the line will display its original colour, but it will render the colour of the fill.

enter image description here

Opactity can be changed programtically based on the value of a field, and the fill and the line will respect the fill.

This method allows you to eliminate the presence of visible lines, white lines, lines not appearing, etc. It allows you to use a colour ramp to classify the colours, and have the line colour follow the main fill colour. It allows you to set the alpha channel opacity / transparency based on the value of a field and have all the symbology change colour and opacity together. It can be applied to the entire symbology set at once.

Answered by anakaine on May 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP