3

I want to use the Processing Algorithm, pointsalonglines, in the expression function used in Geometry Generator.

This is because I want to create points "on the fly" along my line and in a equal distance.

The final reason why, is because I want to show the distance of a track every X meters or kilometers.

All is explained in this two links:

Hatching features in layer using QGIS

Anita Graser help me in this link:

https://anitagraser.com/movement-data-in-gis/#comment-21044

enter image description here

1 Answer 1

6

You can use the following expression to create the points along the line every n distance (here 5000 considering the layer use meters)

collect_geometries(array_foreach(
generate_series(0, length($geometry),step:=5000),
make_point_m(
  x(line_interpolate_point($geometry, @element)),
  y(line_interpolate_point($geometry, @element)),
  @element)
))

Alternative if you need to deal with layer projection (needed if your layer is not using meters in particular) considering EPSG:4326 is your layer projection and your local projection is EPSG:25831

collect_geometries(array_foreach(
  generate_series(0, length(transform($geometry,'EPSG:4326', 'EPSG:25831')),step:=5000),
  transform(make_point_m(
    x(line_interpolate_point(transform($geometry,'EPSG:4326', 'EPSG:25831'),
    @element)),
    y(line_interpolate_point(transform($geometry, 'EPSG:4326', 'EPSG:25831'), @element)),
    @element
  ), 'EPSG:25831', 'EPSG:4326')
))

Although it works for a part and I set the distance value in the M part of the geometry, I don't really see how I can then reuse the M in the labels part as you want in the second part of your requirements. Using Font marker can be another way e.g https://gis.stackexchange.com/a/314789/638 with expression to_string((@geometry_part_num - 1) * 5) || ' Km'

Edit note: comment from @RBenet made me change the second part of the answer

11
  • Thomas this is what I'm looking for. Thank you so much!!! For show the km I will use the option Font Marker and in the expression I put this (@geometry_part_num-1)*5 || 'Km'
    – RBenet
    Commented Jun 25, 2020 at 12:27
  • Tested with to_string((@geometry_part_num - 1) * 5) || ' Km' due to your suggestion (had cast issue when no to_string)
    – ThomasG77
    Commented Jun 25, 2020 at 12:40
  • Sorry, you have reason. I write like this to to try explain better. I have all explained in this link. Thank you again for your help: gis.stackexchange.com/questions/364736/…
    – RBenet
    Commented Jun 25, 2020 at 13:02
  • No problem, we both learn something :) Not aware how to use well Font marker and you how to generate points along line
    – ThomasG77
    Commented Jun 25, 2020 at 13:30
  • 1
    Try collect_geometries(array_foreach( generate_series(0, length(transform($geometry,'EPSG:4326', 'EPSG:25831')),step:=5000), transform(make_point_m(x(line_interpolate_point(transform($geometry,'EPSG:4326', 'EPSG:25831'), @element)),y(line_interpolate_point(transform($geometry, 'EPSG:4326', 'EPSG:25831'), @element)), @element), 'EPSG:25831', 'EPSG:4326') )) I've tested (and it works) using points with EPSG 4326 coordinates and calculation using my local projection (EPSG:2154) and replaced the working expression with your EPSG code 25831.
    – ThomasG77
    Commented Jun 26, 2020 at 16:04

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.