The Expression Way
I cannot write spatial SQL queries nor Python code yet. But there are a way to select perpendicular lines by expression. Then, deleting selected features is a trivial task.
There are, at least, two ways to determine if two 2D lines are perpendicular. One is comparing their azimuthes, another is comparig their slopes (in terms of growth ratio between y and x coordinates). Slopes have a problem that we should handle: a vertical line have infinite slope. Azimuths also have a problem: angles multiples of 2*k*PI()
are the same azimuth, but it is easier to handle. Therefore, better if we use azimuths.
The azimuth entered in the expression is calculated as accurately as possible, so the lines must be exactly perpendicular. When testing this solution I found that the advanced digitization tool of QGIS draws lines perpendicular to one another that the expression does not recognize as such. When they are digitized at fixed angles it does, however. In case the solution does not meet your needs, calculate the azimuths in a field of the attribute tables, with the precision you need for the calculation, and refer to those fields in the expression (expressions will result even simpler, but less precise).
- Two lines are perpendicular when their azimuthes differ by 90 degrees.
But the lines can be digitalized in two directions (forward or reversed), therefore:
- Two lines are perpendicular when their azimuthes differ by -90 degrees, too.
Also, if adding an azimuth of a line 90 degrees, you get an angle greater than 360 degrees, you have to subtract 360. The same thing, if subtracting 90 you get a negative angle, you must add 360. Therefore:
- Two lines are perpendicular when their azimuthes differ by +270 and by -270 degrees, too.
Some other preliminary considerations:
layer1 and layer2 have the same CRS.
In layer2 there is a field named id, and there is only one line with "id" = 1
Now, we can select the lines of layer1 that does not satisfy any of the conditions of perpendicularity against that line, with the following expression:
( azimuth( start_point( $geometry), end_point( $geometry)) + radians( 90) <> azimuth ( start_point( geometry( get_feature( 'layer2', 'id', '1'))), end_point( geometry( get_feature( 'layer2', 'id', '1')))))
AND
( azimuth( start_point( $geometry), end_point( $geometry)) - radians( 90) <> azimuth ( start_point( geometry( get_feature( 'layer2', 'id', '1'))), end_point( geometry( get_feature( 'layer2', 'id', '1')))))
AND
( azimuth( start_point( $geometry), end_point( $geometry)) + radians( 270) <> azimuth ( start_point( geometry( get_feature( 'layer2', 'id', '1'))), end_point( geometry( get_feature( 'layer2', 'id', '1')))))
AND
( azimuth( start_point( $geometry), end_point( $geometry)) - radians( 270) <> azimuth ( start_point( geometry( get_feature( 'layer2', 'id', '1'))), end_point( geometry( get_feature( 'layer2', 'id', '1')))))
UPDATE
QGIS creating algorithms appear to be using 5 decimals of precision. I don't know if it depends on the reference system of the layer units. Test it please. Try with the following expression:
( round ( azimuth( start_point( $geometry), end_point( $geometry)), 5) + round( radians(90), 5) <> round ( azimuth( start_point( geometry( get_feature( 'layer2', 'id', '1'))), end_point( geometry( get_feature( 'layer2', 'id', '1')))), 5))
AND
( round ( azimuth( start_point( $geometry), end_point( $geometry)), 5) - round( radians(90), 5) <> round ( azimuth( start_point( geometry( get_feature( 'layer2', 'id', '1'))), end_point( geometry( get_feature( 'layer2', 'id', '1')))), 5))
AND
( round ( azimuth( start_point( $geometry), end_point( $geometry)), 5) + round( radians(270), 5) <> round( azimuth( start_point( geometry( get_feature( 'layer2', 'id', '1'))), end_point( geometry( get_feature( 'layer2', 'id', '1')))), 5))
AND
( round ( azimuth( start_point( $geometry), end_point( $geometry)), 5) - round( radians(270), 5) <> round ( azimuth( start_point( geometry( get_feature( 'layer2', 'id', '1'))), end_point( geometry( get_feature( 'layer2', 'id', '1')))), 5))