1

I have 1 polyline layer and 1 polygon layer. They both have a column with the same values.

I want the polyline layer to have the same color of the polygon layer when the values are the same. I didn't find any function in the color properties of the polyline layer.

enter image description here

1 Answer 1

0

One way of doing it is to use Categorized symbology with the same value on both layer and then apply the same color ramp to each.

The easy case : the column with the same values on both layer is the one that you use to categorize the polygon. you juste have to use the Categorized renderer on your line layer using the same column then apply the same color ramp on both layer (or set color manualy if few categories)

The harder case : the column with the same values on both layer is NOT the one that you use to categorize the polygon. In that case you need to recover the value used to categorize the polygon and use them to categorise your line layer. This could be done by using below expression rather than a field name for the value setting of the line layer categorized renderer.

attribute( get_feature( 'Polygon_layer_name',  'Name_of_the_column_with_same_value_in_POLYGON_layer' , attribute(@feature, 'Name_of_the_column_with_same_value_in_LINE_layer' )), 'Name_of_the_column_with_same_value_in_POLYGON_layer')

(Note that field name are used as parameter and so are between single quote rather than the usual double quote)

After entering the expression just click the Classify button and apply the same color to the line and polygon

As a side note if your line and polygon have the same color you wont be able to see the line on top of same color polygon so you may want to further alter your symbology to get something legible (below I used drop shadow but altering the the opacity or any other modification could give you acceptable result depending on your need)

enter image description here

8
  • No sure to understand : I think I'm in the first case (the column with the same values on both layer is the one that you use to categorize the polygon) but need the second solution (your script and result look like what I need) :) I tested the second solution, the script is right but not giving me a result : attribute(get_feature( 'servelev_81f0e406_b6b4_4b68_9a32_74148d20b379', 'identifiantservelev',attribute(@feature, 'identifiantserviceelevation')),'identifiantservelev')
    – User
    Commented Sep 8, 2023 at 8:05
  • @Nelson What do you mean by "the script is right but not giving me a result" ? Did you update the classification by clicking on the "Classify" button ?
    – J.R
    Commented Sep 8, 2023 at 8:17
  • Also if you are in the first case (you use the 'identifiantservelev' field to symbolize the polygon) you just need to use the 'identifiantserviceelevation' field to symbolize the line and apply the same color ramp to both layer (dont use random color but an actual color ramp)
    – J.R
    Commented Sep 8, 2023 at 8:43
  • This script is right "attribute( get_feature( 'Polygon_layer_name', 'Name_of_the_column_with_same_value_in_POLYGON_layer' , attribute(@feature, 'Name_of_the_column_with_same_value_in_LINE_layer' )), 'Name_of_the_column_with_same_value_in_POLYGON_layer')" so I tested it adapted to my data and the syntaxe was ok than I cliked on the classify button and it gave me only "other values" symbology. For the first case, the problem is, it will be too long to apply the symbology handly that's why I need the second solution.
    – User
    Commented Sep 8, 2023 at 10:25
  • I would like to show you my computer screens but I can't add any image in the comment.
    – User
    Commented Sep 8, 2023 at 10:29

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.