3

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.

9
  • 1
    it would be a good idea to provide a reference to a fragment of the original geodata so that potential defendants can simulate your original situation... Commented Jul 28, 2020 at 10:02
  • Can you share a piece of data with us? Would be useful
    – Taras
    Commented Jul 28, 2020 at 10:54
  • I added a sample of data, a comment file and a model for Qgis. The main problem for now is the result of the intersection operator.
    – Leehan
    Commented Jul 28, 2020 at 12:26
  • Please edit you your question
    – Taras
    Commented Jul 28, 2020 at 12:28
  • BTW, what is the diffrence between data_source and data_work?
    – Taras
    Commented Jul 28, 2020 at 12:32

2 Answers 2

3

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

2
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
7
  • All lines are selected, not only the yellow ones. But it may be a good start.
    – Leehan
    Commented Jul 27, 2020 at 11:47
  • Are they also lines, I mean those yellows?
    – Taras
    Commented Jul 27, 2020 at 11:52
  • yes. The two shapefiles are lines. We need a criteria : "select when there is only startpoint and endpoint on lines (not more)".
    – Leehan
    Commented Jul 27, 2020 at 11:53
  • please check updates
    – Taras
    Commented Jul 27, 2020 at 12:00
  • selection is empty with st_intersection. If it can help, blacklines can be polygons since they are closed.
    – Leehan
    Commented Jul 27, 2020 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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