3

I would like to apply two different styles on the same vector layer (lines), from two different fields of the table.

To be more specific, I would like to make a graduate size of the lines from the X field, and a graduate color from the Y field.

There is a related question here : Using BOTH size and colour to represent 2 pieces of information on single point in QGIS

But I would like to know if the solution has been "updated" with QGIS 3.

6

Using QGIS 3.6 (but probably any version since 2), the easiest way is to use the Graduated renderer with your "Y(color)" field then using the "X(size)" field on the data defined properties for line width.

The only problem with this is that the legend wont show the size variation (legend cant reflect defined properties) so you will have to create the legend seperately

enter image description here

enter image description here

If you have a field with number in it for your size (numerical or string field both work) you could just click in the circled box on the left of the Width input and select "Field type : int, double, string" then select your field

To adjust the result I suggest to use the scale fonction (linear or exp depending on what result you want), just click on the box again and choose edit then set something like this :

scale_linear( "X(size)",1,15,5,20)

This fonction will size data ranging from 1 to 15 to a size ranging from 5 to 20 (adjust value depending on the range of your size field and the range of size you need)

If your size field is text string you will need to use more creative expression, you could try something like :

CASE
    WHEN "X(size)" = 'Small' THEN 5
    ...
    WHEN "X(size)" = 'Somevalue' THEN xx      
     ... 
    WHEN "X(size)" = 'Big' THEN 20
END
  • What version(s) does this answer apply to? I think this question and its answer(s) should be merged with the “related” one. – PolyGeo Oct 22 at 12:16
  • @PolyGeo This is with QGIS 3.6, I think it should also work from version 2 , if I remember well these functionality where already present. I dont know how to merge question but fell free to do it if you think it's better – J.R Oct 22 at 12:19
  • 1
    It needs a mod to merge which I plan to do tomorrow. – PolyGeo Oct 22 at 12:23
  • Thanks for that nice process ! Could you give me a little more info about the way to manage the width difference ? – Foaly Oct 22 at 18:31
  • 1
    @Foaly see me edit – J.R Oct 23 at 8:44

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.