TransWikia.com

Selecting lines intersecting lines on two points in QGIS 3.14

Geographic Information Systems Asked on September 26, 2021

I have two shapes of lines: one A with exploded red lines, the other B with closed black lines.

In a virtual layer I want to select the yellow ones (A) i.e. those having only 2 points in common with B.

I try to find a way to count the number of intersections between 2 lines without success.

Or maybe there is a better way to do it.

enter image description here

enter image description here


@JGH There is something weird when I work with my data. I can’t get the result you show on your screenshot. When I run the query to get the same result as you:

SELECT poly.*
FROM input1 as poly, input2 AS ouverture 
WHERE st_intersects(poly.geometry, ouverture.geometry)
AND st_dimension(st_intersection(poly.geometry, ouverture.geometry)) = 0

Then the result is the red lines :
enter image description here

The green polygons (poly) have only 4 nodes and topology is correct with black lines. It runs from a model so green polygon file converted to lines is not visible.
The strangest are the two red lines at the bottom which are the opposite of the expected result.

@Taras : result is empty.

EDIT : sample of data
shp and comments inside.

2 Answers

You need to select the line that intersect the box, then you compute the intersection and keep only the ones who have an intersection composed of points (i.e. exclude the intersection made of lines)

SELECT tg.*
FROM target_layer AS tg, closes_line_layer AS cl 
WHERE st_intersects(tg.geometry, cl.geometry)
AND ST_Dimension(st_intersection(tg.geometry, cl.geometry)) = 0

enter image description here

Correct answer by JGH on September 26, 2021

SELECT r.*
FROM "red_lines" AS r, "black_lines" AS b 
WHERE st_within(start_point(r.geometry), b.geometry)
AND st_within(end_point(r.geometry), b.geometry)
AND st_length(st_intersection(r.geometry, b.geometry)) = 0

Answered by Taras on September 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP