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:
- Use Points along geometry tool to create points along the layer A center line (example distance: 10 meters)
- 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
)
- Use Split with lines tool to split the created perpendicular lines with the layer B lines.
The intermediate result then looks like this:
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.
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.


closest_point(). – winnewoerp Dec 04 '23 at 20:01