I have a line layer showing sectors of roads that I want to style by two different fields without duplicating the layer.

  • "Field 1" is an integer ranging from 0-25 defining road usage (street, path, bikelane, etc.)
  • "Field 2" is an integer ranging from 0-16 defining road signs that are valid within the sector

I want the line to be colored by "field 1" (I need to be able to manually define colors for each number) and I need a centroid with different SVG-graphics depending on "field 2".

Is there a way to achieve that without manually adding rule-based options for all 25x16 possible outcomes?

I can now run the line color from "field 1" via Data driven override. I am still not able to do the same with SVG graphics.

I added a marker line with a single centroid SVG-marker. I cannot manage to insert the expressions to set different files for my conditions.

I've tried full 'paths\filename.svg' with both / and \ or only start in from @project_folder. This is the only way I don't get any parsing errors. I also tried using file_path() and file_name() which generate errors.

  • 3
    If you need specific symbols and colours, I suggest using data driven override on both. This should be easier to handle and change.
    – Erik
    Oct 25, 2021 at 12:07
  • 3
    As far as I know, data driven override can only define a gradient for a range? I need several mono-colors, I'll clarify the question on what exactly I want to show
    – e-shirt
    Oct 25, 2021 at 12:12
  • 3
    You can use CASE WHEN conditions as override. E.g. case when "x" = 1 then 'red' when "x"=2 then 'blue' when "x"=3 then color_rgb(255,181,57) else 'black' end. Same goes for symbols.
    – Erik
    Oct 25, 2021 at 12:17
  • 1
    Or define a color ramp conatinaing exactly those 26 colors (0-25) you want.
    – Babel
    Oct 25, 2021 at 12:25
  • 2
    Can you share the exact expression you used for the svg data driven override? Sometimes it helps to use a funciton like right() around your expression to extract, say, the last 30 characters and make sure you have a valid path. I regularly forget whether I should add a \ before the custom part of the path or not...
    – she_weeds
    Oct 28, 2021 at 1:20

2 Answers 2


To achieve the desired output


apply the following settings for


Use the following expression in the Expression String Builder

    WHEN "Field1" = 2 THEN '#264653'
    WHEN "Field1" = 9 THEN '#2A9D8F'
    WHEN "Field1" = 16 THEN '#E9C46A'
    WHEN "Field1" = 18 THEN '#F4A261'
    ELSE '#E76F51'


Line centroid symbology

Firstly Add symbol layer and make an SVG-marker out of it. After trying the following expression in the Expression String Builder for Dynamic SVG parameters

    WHEN "Field2" = 1 THEN 'P://Test//qgis_test//socicon_amazon.svg'
    WHEN "Field2" = 3 THEN 'P://Test//qgis_test//socicon_apple.svg'
    WHEN "Field2" = 8 THEN 'P://Test//qgis_test//socicon_github.svg'
    WHEN "Field2" = 13 THEN 'P://Test//qgis_test//socicon_google+.svg'
    ELSE 'P://Test//qgis_test//socicon_mail.svg'


Note: Central point was used for Marker placement.

Currently changing(overriding) simultaneously the colour and style of the SVG-file can not be done.

An Attempt

With this approach, you can get control over your symbology, see the image below.


Unfortunately, in this case, it is not possible to adjust the colour that easily. I was hoping to apply the method as was mentioned in one of my previous solutions.


Working Solution #1

Using the Categorized symbology


Working Solution #2

Using the Rule-based symbology


Disadvantage: In both approaches you will need manually to change the colour (⚠️ not dependent on the "Field2")

I am on Windows 10 with QGIS 3.18.1-Zürich.



Cross-referencing to my other question, I am now able to produce said symbology using a simple line and a marker line with centroids:

On my simple line I use data driven override (DDO) to style line color with color_rbg(0,0,0) to style by "field1" and also use a second DDO to make some lines dotted with values of "field1".

On the added marker line I chose single centroids and changed type to SVG marker. There I again used DDO to style my centroids by "field2". Normally, any of @Taras approaches on the other post should work, although I can only manage to use the reference to online sources via URL, now having to bear with long/endless loading times.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.