2

My questions is about creating an elongated buffer around various lines and these buffers should run right in the middle of two parallel lines. The problem is that the lines do not have an equal width at all points. image showing the lines around which the buffer should be placed

To give some more context, different weed control measures were used in different lanes, so I want to visualise the lanes as polygons/buffers so I can use them to extract data from different lanes/treatments.

1
  • Can you provide an example of what you're trying to achieve?
    – Erik
    Dec 20, 2021 at 15:44

2 Answers 2

6

To create "buffers" along the mid line between irregularily spaced lines, create voronoi polygons:

  1. Densify lines and Extract vertices.

  2. Create voronoi polygons for the densified points

  3. Join the line id to the voronoi polygons, using Field calculator with this expression overlay_intersects ('line',$id)[0]

  4. Aggregate voronoi polygons based on line id (see screenshot 1)

  5. To clip the large buffers at the margin, collect all lines in a multiline, buffer this and intersect it with the voronoi polygons (see screenshot 2 for the result). You can do this e.g. with this expression using Geometry by expression:

    intersection (
       $geometry, 
       buffer (collect_geometries (overlay_nearest ('line', $geometry)),15)
    )
    
  • change the value of 15 for buffer size at the end of line 3
  • change line with the name of your line layer

Screenshot 1, red: initial lines; blue with black dashed lines: buffers (one buffer in yellow is selected): enter image description here

Screenshot 2: enter image description here

3
  • 1
    Thank you so much Babel, I manged to get the polygons. Still working on getting the edges right but your beautiful and visual explanation has helped a lot. I only did not manage to create voronoi polygons from a densified line (because Qgis told me it wanted points as input) so I used the ''points along geometry'' to transfer the line into points and create a buffer from that.
    – N_LLC
    Dec 21, 2021 at 12:47
  • Sorry you're right. I skipped one step: extract vertices, see updated answer
    – Babel
    Dec 21, 2021 at 12:56
  • You made my day Babel! thanx
    – N_LLC
    Dec 21, 2021 at 13:26
0

Based on your screenshot it seems that the length of all parallel lines are equal but the width spacing between them is not uniform. In such a case, to find a centerline programatically, you can

  1. Resample your polylines at regular interval for eg. 1 point / meter to obtain uniform sampling rate across all polylines
  2. Next find midpoints of line segments connecting every N-th point pair of adjacent polylines
  3. Create a line connecting all midpoints obtained in step 2 for each adjacent pair of lines to obtain centerline between each adjacent pair of lines

Another option is to create a raster of a polygon created by every adjacent set of line and then use something a skeletonization algorithm to find a centerline and convert that raster skeleton back to vector representation.

Edit:

You can also skeletonize the polygons created by adjacent lines directly, without converting them to rasters using Polygonal Skeletons

1
  • Thank you a lot for your comment, one previous answer solved my question.... but I did not know the method you described but it can be very useful in other projects!
    – N_LLC
    Dec 21, 2021 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.