QGIS – Using Marker Line to Calculate Fence Post Positions and Counts

geometry-generatorlinestringmarkersqgissymbology

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.

Best Answer

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