0

I would like to create a line style for projected tracks. Every kilometer on the line there should be a marker with a number. I hope it possible using geometry generator.

enter image description here

Making markers after 1000 meters is easy:

collect_geometries(
    array_foreach(
        generate_series(1,   $length/1000 ),
        line_interpolate_point($geometry, @element*1000)            
    )
)

But you also need to rotate them along the line and sign. At each point, you can calculate the azimuth by taking an additional point along the line. But how to pass this value to the marker?

1 Answer 1

2

You can use a marker line.

Configure it to display a marker every 1000 map units (assuming your projection is using meters), and keep the default to rotate the marker

enter image description here

then select the marker and choose the vertical segment

enter image description here

If you want the km to be written as part of the symbol (instead of a label), then add a 2nd marker, of the type font marker. Click the data override icon beside the character field and enter the expression (@geometry_point_num - 1) || ' KM', which will take the "point number" (i.e. the km since they are 1000m appart), minus one as there is a marker at the start of the line, and append the letters " KM".

At last, adjust the font marker offset so it doesn't overlap with the line/cross segment.

enter image description here

1
  • Yes, thanks, it partially works. It looks correct if the entire polyline is on the screen. But if we see only part of the polyline, the first node is counted from the edge of the map canvas and the numbering breaks. Commented Jan 21, 2022 at 7:55

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.