4

I am making a farm plan in QGIS. One of the layers is the fencing layout (Shapefile / Line String). One of the fields is the post distance. Other is virtual field calculating post amount (length($geometry)/post_dist). Then I use marker line with "Interval" set to Meters at scale > post_dist to approximate fence positions.

On a straight line, quite ok.

But on a polyline, the points are placed continously skipping the corners, but on a real fence, I will place a post on every corner/breakpoint and then evenly between breakpoints to get my post distance between some min and max distance (e.g. 4-5 meter).

It looks like this right now. Obviously could not make fence corner without a post :)

Default behavior

I would like it to behave like this, number of posts depending on min/max distance setting.

Expected behavior 1

Expected behavior 2

Is there some way to use markers (maybe with geometry generator?) to work as I described? If it is impossible, could you navigate me to some plugin/script that could maybe generate a fence posts point layer from fence LineString? Would not be as "live" as Marker Line, but could live with that.

4
  • 1
    Hava you tried points along line, maybe with splitting the line at each vertex beforehand?
    – Erik
    Jan 29 at 10:23
  • I did not, but it should be a little fool proof process for the farmer. Splitting 20-segment line at vertices and then processing one by one means he will draw it on paper easier. And in the design phase repaating multiple times does not look very inviting :) Anyway thanks for another tip, might use it other times. Jan 29 at 21:44
  • You could provide a graphical model to the farmer. They drag&drop it into QGIS, hand it their fence-data and maybe define the spacing of the posts. Done.
    – Erik
    Jan 29 at 21:49
  • Could you elaborate on this, maybe as an answer please? I used Qgis only for drawing, so I am not sure where are you heading. Jan 31 at 8:22

2 Answers 2

4

You can use the Processing algorithm Densify by interval. It will add vertices to the linestring features, evenly distributed between every pair of original vertices, with the maximum distance between them no larger than the input value. It also has the advantage of creating actual vertices, which can be used for retrieving coordinates, snapping, etc.; instead of just approximating the locations.

Example with some random sample: red are the original lines (plot boundaries), green are the vertices of the lines after densifying (posts).

enter image description here

1
  • Thanks! Works nicely, even the interval parameter can be paired with a field, so every fence has different spacing. Looks like marker line is good enough for designing and Densify by interval for final output. Jan 29 at 21:58
1

If someone is interested in a solution with geometry generator:

with_variable('distance_target', 20

would be the disered distance between the posts, which will be adjusted to each segment length.

collect_geometries(nodes_to_points($geometry),
    with_variable('segments', segments_to_lines($geometry),
        collect_geometries(
            array_foreach(generate_series(0, num_geometries(@segments)),
                with_variable('distance_target', 20,
                    with_variable('segment_length',length(geometry_n(@segments,@element)),
                        with_variable('distance_result',@segment_length/round(@segment_length/@distance_target,0),
                            with_variable('i', @element,
                                collect_geometries(
                                    array_foreach(
                                        generate_series(@distance_result,@segment_length-@distance_result,@distance_result),
                                            line_interpolate_point(geometry_n(@segments,@i),@element)
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )
)

enter image description here

The rounding code could be improved.

with_variable('distance_result',@segment_length/round(@segment_length/@distance_target,0),

However for design porpose it could help.

1
  • will definitely try this, i think geometry generator has great potential for me to explore :) Jan 31 at 8:25

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.