With geometry generator in QGIS I'm trying to place a marker in the midpoint of each segment of a multiline vector (I don't want to use the Highlight line option). My main issue is how to read each line of a multiline separately and have a centroid of each segment.

code example I am trying with

This is the result, as you can see I get a centroid of the multiline and not one for each segment. I am missing something!


I want to do this within the geometry generator so that anytime I move the line, the midpoint moves accordingly. And once I know how to code <<make a point>> I can use the <<raster_value>> command and apply that information to the marker. I could use the "highlight_line" vector stile, and place a marker in the midpoint of each segment, but I would still need to have a point to read the raster below. And I want this to happen automatically and not by modifying the type of vector.

  • A multiline would be multiple lines merged into one feature. Your line looks like a normal line. What is wrong with using a marker line and placing the markers on the middle of each segment?
    – Erik
    Commented Oct 21, 2021 at 12:15
  • Nothing wrong with placing a marker in middle of each segment, but I also need to read the value of a raster in that specific midpoint and apply it to the marker's rotation. That is why I need to write the code to retrieve that node. Commented Oct 21, 2021 at 13:13

1 Answer 1


You can use the following expression for Geometry Generator.

    'segments', segments_to_lines($geometry),
            generate_series(1, num_geometries(@segments)),

enter image description here

Or a simpler way is to use "Marker Line" instead of "Geometry Generator" and select on central point of segments. (thanks to @Eric)

enter image description here

  • 4
    This actually is already available when choosing a marker line.
    – Erik
    Commented Oct 21, 2021 at 13:03
  • 1
    @Erik thanks for reminding. I've added a geometry generator solution since Francesco used it. But of course, Marker Line is a shorter way than Geometry Generator. Commented Oct 21, 2021 at 13:14
  • Thank you! your code works perfectly! Now I have a marker in the centroid of each segment. I thought that this code would also work when trying to set the rotation of the marker by using the raster_value command raster_value(layer,band,point) Commented Oct 21, 2021 at 13:14

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.