I have a set of GPS coordinate points from a survey, and I used the "Points to Path" tool to create a line. I would like to have the line symbology being alternating colors between points. The points are not uniformly spaced. (For example, between 176 and 177 = red, between 177 and 178 = yellow, and repeat)

enter image description here

  • 2
    I suggest you split your line layer with your points, and then use data defined override with an if-condition based on the ID of the split lines to return red or yellow colour.
    – Erik
    Commented Mar 3, 2022 at 11:55

2 Answers 2


You can achieve it using the geometry generator.

First, transform each segment to its own line. The original line becomes a multiline


enter image description here

Moving to rendered simple line symbology, we can now define a data override for the color (click the epsilon sign beside color then choose edit). Since the rendered geometry is now a multipart, we can make use @geometry_part_num and use a modulo 2 to identify every second segment:

  WHEN  @geometry_part_num % 2 = 0 THEN 'red'
  ELSE 'green'

enter image description here


I think Erik and Bera are right. Here is a way to do it with the explode lines tool but I'm hoping someone will show how to do it with the geometry generator so you can have a live ployline.

First use the explode lines tool in the processing toolbox. This will convert your connected path to segments.

Because the tool makes these segments in an orderly fashion we can use the ID of each segment to color the odd and the even numbered segments differently.

Set your style to rule based and create 2 rules.

Find the odd segments by setting the Rule 1 filter expression to $id % 2. This will take the ID ($id) and check if there is a remainder when it is divided by 2. If there is a remainder it returns 1 for true. (% = remainder of division)


In Rule 2 set it to else.


final output

  • 2
    And if you need more colors, instead of using even and odds numbers, check if the last number in your id is 1, 2, 3... to make more rules
    – Mr_Yum
    Commented Mar 3, 2022 at 13:47

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.