1

I have a set of lines (roadways) on layer A and a set of (mainly) parallel lines (sidewalks) on layer B. I want to create perpendicular lines at a given distance that extend from the layer A center line to the closest layer B line on both sides.

My approach so far was the following:

  1. Use Points along geometry tool to create points along the layer A center line (example distance: 10 meters)
  2. Use Geometry by expression tool with the following expression (based on this GIS SE answer) to create the perpendicular lines with a useful initial length, using the "angle" attribute created for the points along layer A geometries:
extend(
  make_line(
    $geometry,
    project(
      $geometry, 
      25, 
      radians("angle" - 90)
    )
  ),
  25,
  0
)
  1. Use Split with lines tool to split the created perpendicular lines with the layer B lines.

The intermediate result then looks like this:

Perpendicular lines, intermediate result

A rough approach now is to just extract all the sections of the perpendicular lines that intersect the layer A center line. However, there are a few problems close to intersections where the perpendicular lines intersect the section of the center line they are based on and additionally one ore more other layer A lines. Also, the Split with lines tool does not cut at all sections as desired when there are more than two intersections with the "parallel" layer B lines. See screenshot where e.g. the marked line has not been cut as desired.

Problematic parts of the perpendicular lines

I am now looking for a solution (based on QGIS expressions) to initially create the perpendicular lines not with a given (fix) length and cut the undesired parts afterwards, but to extend the lines only as far as needed, which is to the closest layer B lines on each side of the center line.

I have experimented with closest_point() and overlay_touches() a bit, but I did not find a working solution yet.

winnewoerp
  • 1,504
  • 11
  • 21
  • Have you tried 'Snap geometries to layer'? – Walshe_d Dec 04 '23 at 18:26
  • No, not yet. You think this might work? I need to snap each point to two different lines then and I don't see how this might work. I actually had the same problem with closest_point(). – winnewoerp Dec 04 '23 at 20:01
  • I think so but as I don't have your data I'm not 100% sure. Try it, if it doesn't work, provide a sample of your datasets and I can try alternative solutions. – Walshe_d Dec 04 '23 at 20:27

0 Answers0